On Tue, 5 Aug 2025 01:42:53 GMT, Shaojin Wen <[email protected]> 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";
>  />

This pull request has now been integrated.

Changeset: 2c7f7380
Author:    Shaojin Wen <[email protected]>
URL:       
https://git.openjdk.org/jdk/commit/2c7f7380ea828e5ec928e1cb05b13806646ecb3d
Stats:     49 lines in 1 file changed: 7 ins; 0 del; 42 mod

8368825: Use switch expression for DateTimeFormatterBuilder pattern character 
lookup

Reviewed-by: rriggs, naoto, scolebourne

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

PR: https://git.openjdk.org/jdk/pull/26634

Reply via email to