Hi Mark did you "jmh" it? recall the cache the counter productive when originally setup on several code paths. If it is now it can be worth explaining the gain ratio in a comment even if depending on the machine to avoid it to be removed (ping pong code ;))
Romain Manni-Bucau @rmannibucau <https://x.com/rmannibucau> | .NET Blog <https://dotnetbirdie.github.io/> | Blog <https://rmannibucau.github.io/> | Old Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book <https://www.packtpub.com/en-us/product/java-ee-8-high-performance-9781788473064> Javaccino founder (Java/.NET service - contact via linkedin) ---------- Forwarded message --------- De : <[email protected]> Date: jeu. 23 juil. 2026 à 21:08 Subject: (johnzon) 03/03: JOHNZON-435 reuse toUnicode with caching To: [email protected] <[email protected]> This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git commit 8833227516f01925398b87030708b411922c1616 Author: Mark Struberg <[email protected]> AuthorDate: Thu Jul 23 21:06:24 2026 +0200 JOHNZON-435 reuse toUnicode with caching --- .../src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java | 7 ++----- johnzon-core/src/main/java/org/apache/johnzon/core/Strings.java | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java index 25af0184..34305258 100644 --- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java @@ -34,6 +34,8 @@ import java.math.BigInteger; import java.util.Iterator; import java.util.Map; +import static org.apache.johnzon.core.Strings.toUnicode; + class JsonGeneratorImpl implements JsonGenerator, JsonChars, Serializable { private final transient Writer writer; private final BufferStrategy.BufferProvider<char[]> bufferProvider; @@ -547,11 +549,6 @@ class JsonGeneratorImpl implements JsonGenerator, JsonChars, Serializable { private static final String UNICODE_PREFIX = "\\u"; private static final String UNICODE_PREFIX_HELPER = "000"; - private static String toUnicode(final char c) { - final String hex = UNICODE_PREFIX_HELPER + Integer.toHexString(c); - final String s = UNICODE_PREFIX + hex.substring(hex.length() - 4); - return s; - } private void justWrite(final String value) { final int valueLength = value.length(); diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/Strings.java b/johnzon-core/src/main/java/org/apache/johnzon/core/Strings.java index 975ba348..44009e43 100644 --- a/johnzon-core/src/main/java/org/apache/johnzon/core/Strings.java +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/Strings.java @@ -102,7 +102,7 @@ class Strings implements JsonChars { } } - private static String toUnicode(final char c) { + public static String toUnicode(final char c) { final String found = UNICODE_CACHE.get(c); if (found != null) { return found;
