Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Escape control chars when stringifing JSON (#492) #672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clay-mayers
Copy link

As it was originally coded, this change assumes escaping is uncommon. The string is scanned first for characters that require escaping (i.e \ " and control characters). A single scan is performed checking for the presence of any of these three cases. The type of characters found are accumulated and used to only replace those that were found in the string.

The presence of a given category/type of escape character is done using bit-wise operations to avoid comparisons for performance (testing a character this way is 12% faster with jdk11 on an m1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant