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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to