Skip to content

remove unnecessary string intern - #136

Open
sergeevik wants to merge 1 commit into
dashjoin:mainfrom
sergeevik:remove-string-intern
Open

sergeevik wants to merge 1 commit into
dashjoin:mainfrom
sergeevik:remove-string-intern

Conversation

@sergeevik

@sergeevik sergeevik commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

substr / leftPad / rightPad. Performed String.intern() on each input string. This is a slow lookup in the JVM's global string table, which also clutters it with strings from user data, and the result is used only for calculating code points.

@aeberhart

Copy link
Copy Markdown
Contributor

Thanks, looks good. The interned strings are only used for code point counting, so nothing depends on identity.

Note for future changes to substr / leftPad / rightPad: this code originally comes from Jsonata4Java, which is likely no longer maintained, so we have to clean it up here. If we touch these functions again, the following should be addressed as well:

  • Objects.requireNonNull(...) is now redundant: str and padStr are already null-checked in the pad functions, and substr calls str.length() before it.
  • The padding in leftPad / rightPad is built with String += in a loop, which is quadratic in the pad length. StringBuilder or String.repeat would be better.

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.

2 participants