Skip to content

refactor: simplify hex escape pattern scanning - #1003

Open
nkuprins wants to merge 3 commits into
apache:mainfrom
nkuprins:refactor/cleanup-escape-hex-write-handler
Open

refactor: simplify hex escape pattern scanning#1003
nkuprins wants to merge 3 commits into
apache:mainfrom
nkuprins:refactor/cleanup-escape-hex-write-handler

Conversation

@nkuprins

@nkuprins nkuprins commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Should be reviewed only once #1001 gets merged

Related: #1000

Purpose of the pull request

The second of the two PRs. This one does the refactor/cleanup. No behaviour change.

What's changed?

  • The match loop is written once instead of twice. The scan used to live in two methods: escapeHex located the
    first valid pattern, then processWithPatterns located every later one. Both carried the same match-handling code - bounds check, closing-_ test, hex validation, append, so any change to the rule had to be made in two places. It is now a single loop.
  • The no-match path allocates nothing. The StringBuilder is created on the first match rather than up front, so a cell containing no _xHHHH_ - costs one indexOf scan and no allocation.
  • The offsets have names. Each iteration derives hexStart, suffixIndex and patternEnd from PREFIX_LENGTH and HEX_DIGIT_COUNT.
  • isValidHexFast is now isHexDigits, and the lookup table has a note on why it is not Character.digit(c, 16) - that method also accepts non-ASCII digits such as U+0663, which OOXML never encodes.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@nkuprins nkuprins changed the title refactor: cleanup escape hex write handler refactor: simplify hex escape pattern scanning Aug 10, 2026
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