reschke commented on code in PR #1511: URL: https://github.com/apache/jackrabbit-oak/pull/1511#discussion_r1632840377
########## oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/json/JsopBuilder.java: ########## @@ -275,6 +277,34 @@ public static String encode(String s) { return '\"' + s + '\"'; } + /** + * Similar to #encode(String) but appends the result to the given buffer. This method exists to avoid the allocation + * of intermediate objects to represent the encoded String when the caller already has a buffer where the result + * should be appended. + * + * @param s the text to convert + * @param buff the target buffer + * @return the target buffer with the encoded string appended + */ + private static StringBuilder encode(String s, StringBuilder buff) { + if (s == null) { + return buff.append("null"); + } + int length = s.length(); + if (length == 0) { + return buff.append("\"\""); + } + for (int i = 0; i < length; i++) { + char c = s.charAt(i); + if (c == '\"' || c == '\\' || c < ' ' || (c >= 0xd800 && c <= 0xdbff)) { Review Comment: Maybe extract the logic that detects what needs to be escaped? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org