Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions sjsonnet/src/sjsonnet/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,13 @@ object Format {
}
val labels = parsed.labels
val specBits = parsed.specBits
val singleSpecNoStatic = specBits.length == 1 && parsed.staticChars == 0
// Pre-size StringBuilder based on static chars + estimated dynamic content
val output = new java.lang.StringBuilder(parsed.staticChars + specBits.length * 8)
appendLeading(output, parsed)
val output =
if (singleSpecNoStatic) null
else new java.lang.StringBuilder(parsed.staticChars + specBits.length * 8)
if (!singleSpecNoStatic) appendLeading(output, parsed)
var singleFormatted: String = null
var i = 0
var idx = 0
// Use while-loop instead of for/zipWithIndex to avoid iterator allocation
Expand Down Expand Up @@ -731,8 +735,11 @@ object Format {
i += 1
formattedValue
}
output.append(cooked0)
appendLiteral(output, parsed, idx)
if (singleSpecNoStatic) singleFormatted = cooked0
else {
output.append(cooked0)
appendLiteral(output, parsed, idx)
}
idx += 1
}

Expand All @@ -741,7 +748,7 @@ object Format {
"Too many values to format: %d, expected %d".format(valuesArr.length, i)
)
}
output.toString()
if (singleSpecNoStatic) singleFormatted else output.toString()
}

/**
Expand Down
Loading