Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17014 Use singleton to avoid synchronized in ExtraPaths #4330

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

btangmu
Copy link
Member

@btangmu btangmu commented Feb 1, 2025

CLDR-17014

  • This PR completes the ticket.

ALLOW_MANY_COMMITS=true

Copy link
Member

@macchiati macchiati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, thanks!

Comment on lines 23 to 25
paths = new HashSet<>();
addPaths(NameType.SCRIPT);
addPaths(NameType.LANGUAGE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end of this method, you need to make paths be an ImmutableSet. Add an extra parameter to addPaths, etc. and change this to:

Suggested change
paths = new HashSet<>();
addPaths(NameType.SCRIPT);
addPaths(NameType.LANGUAGE);
Set<String> temp = new TreeSet(); // might as well put them in order; easier to debug
addPaths(NameType.SCRIPT, temp);
addPaths(NameType.LANGUAGE, temp);
paths = ImmutableSet.copyOf(temp); // preserves order (Sets.copyOf doesn't)

@btangmu btangmu requested a review from macchiati February 2, 2025 02:26
@btangmu
Copy link
Member Author

btangmu commented Feb 2, 2025

@macchiati the 2nd commit makes paths an ordered ImmutableSet as you suggested

Copy link
Member

@macchiati macchiati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be slightly better to add pathsTemp as a parameter to addPaths, but this works and only costs a trifling bit of memory.

@btangmu btangmu merged commit d669e24 into unicode-org:main Feb 3, 2025
12 checks passed
@btangmu btangmu deleted the t17014_h branch February 3, 2025 00:45
@btangmu
Copy link
Member Author

btangmu commented Feb 3, 2025

It would be slightly better to add pathsTemp as a parameter to addPaths, but this works and only costs a trifling bit of memory.

Making it a parameter might reduce the data size by a few bytes, but increase the code size by a slightly larger number of bytes, since addPaths and addAltPath have dozens of callers. Anyway, this can be revisited in follow-up refactoring when moving more code from CLDRFile to ExtraPaths.

@macchiati
Copy link
Member

good point!

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.

2 participants