Skip to content
Open
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
10 changes: 10 additions & 0 deletions sjsonnet/src/sjsonnet/BaseByteRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,18 @@ class BaseByteRenderer[T <: java.io.OutputStream](
/**
* SWAR-accelerated path for long strings. Converts to UTF-8 bytes once, then bulk-copies clean
* chunks and escapes only the bytes that require it.
*
* Probes the string with a SWAR ASCII-safe scan first. When the string is clean printable ASCII
* (no escape chars, no non-ASCII), the entire UTF-8 encode pass (HeapCharBuffer.wrap +
* CharsetEncoder.loop + output byte[] allocation) is skipped — bytes are written directly from
* the chars via Platform.copyAsciiStringToBytes. This is the dominant case for K8s/JSON output
* where long values (descriptions, paths, base64 blobs) are pure ASCII.
*/
private def visitLongString(str: String): Unit = {
if (Platform.isAsciiJsonSafe(str)) {
renderAsciiSafeString(str)
return
}
val bytes = str.getBytes(java.nio.charset.StandardCharsets.UTF_8)
val bLen = bytes.length
val firstEscape = CharSWAR.findFirstEscapeChar(bytes, 0, bLen)
Expand Down
Loading