<i18n dev> RFR: 8368825: Use switch expression for DateTimeFormatterBuilder pattern character lookup [v4]

Stephen Colebourne scolebourne at openjdk.org
Thu Oct 2 06:57:51 UTC 2025


On Tue, 30 Sep 2025 23:21:32 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> The DateTimeFormatterBuilder::FIELD_MAP previously used a Map<Character, TemporalField> for mapping pattern characters to TemporalField
>> instances. This PR refactors that implementation to use a switch expression instead, which eliminates the need to hold a Map in
>> memory.
>> 
>> The switch expression approach offers these advantages:
>> - No memory overhead for maintaining a HashMap structure
>> - More direct character-to-field mapping without hash computation
>> - Better code readability and maintainability
>> 
>> This change maintains the same functionality while improving the memory efficiency of pattern character lookup in
>> DateTimeFormatterBuilder by eliminating the static Map that was previously used for character-to-field mapping.
>> 
>> * before
>> <img width="2018" height="1016" alt="image" src="https://github.com/user-attachments/assets/57d4c513-55c7-472e-95a8-9f7a4b47662d" />
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   revert comment @liach

Marked as reviewed by scolebourne (Author).

-------------

PR Review: https://git.openjdk.org/jdk/pull/26634#pullrequestreview-3292808879


More information about the i18n-dev mailing list