You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/10/16 13:01:32 UTC
[PR] DataFormatter: precompile regexes used when formatting [poi]
pjfanning opened a new pull request, #1399:
URL: https://github.com/apache/poi/pull/1399
`String.replaceAll` and `String.replaceFirst` compile their regex on every call. Several of these calls run once per formatted cell.
## Changes
- `DataFormatter`
- The E-notation fix-up `replaceFirst("E(\\d)", "E+$1")` runs for every formatted number; it now uses a static `Pattern`.
- The other per-call regexes use static `Pattern`s too: the fraction chunk spaces, the `E` → `E+` fix-up in `formatRawCellContents`, and trimming trailing commas (which now reuses the existing `endsWithCommas` pattern).
- `ExcelStyleDateFormatter`
- `format()` runs for every date cell. The `MMMMM` truncation regex is now a static `Pattern`.
- The eight elapsed-time and millisecond placeholder replacements now use `String.replace`. They replace a single private-use character with digits, so no regex was needed.
- The `s.000`, `s.00` and `s.0` rewrites in `processFormatPattern` are now static `Pattern`s. They keep their regex semantics, where `.` matches any character, so behaviour is unchanged.
- `DateUtil.parseDateTime`: uses a static whitespace `Pattern`.
## Thread safety
`Pattern` is immutable and safe to share between threads. Each call still creates its own `Matcher`, and no `Matcher` is cached or shared.
`ExcelStyleDateFormatter` does have an existing problem: its static `DecimalFormat` fields (`format1digit` and the others) are shared across all instances, and `DecimalFormat` is not thread-safe. This PR doesn't change that.
## Tests
`TestDataFormatter`, `TestExcelStyleDateFormatter`, `TestDateUtil` and `TestHSSFDataFormatter` pass locally.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] DataFormatter: precompile regexes used when formatting [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1399:
URL: https://github.com/apache/poi/pull/1399
--
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-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org