-
Notifications
You must be signed in to change notification settings - Fork 233
synchronize access to IdentityHashMap instances #1787
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |||||||||
| import java.util.Objects; | ||||||||||
| import java.util.regex.Pattern; | ||||||||||
|
|
||||||||||
| import static java.util.Collections.synchronizedMap; | ||||||||||
| import static java.util.Locale.ROOT; | ||||||||||
| import static net.datafaker.service.FakeValuesService.DEFAULT_LOCALE; | ||||||||||
|
|
||||||||||
|
|
@@ -18,8 +19,8 @@ | |||||||||
| */ | ||||||||||
| public class FakerContext { | ||||||||||
| private static final Pattern LOCALE = Pattern.compile("[-_]"); | ||||||||||
| private static final Map<SingletonLocale, List<SingletonLocale>> LOCALE_2_LOCALES_CHAIN = new IdentityHashMap<>(); | ||||||||||
| private static final Map<SingletonLocale, SingletonLocale> STRING_LOCALE_HASH_MAP = new IdentityHashMap<>(); | ||||||||||
| private static final Map<SingletonLocale, List<SingletonLocale>> LOCALE_2_LOCALES_CHAIN = synchronizedMap(new IdentityHashMap<>()); | ||||||||||
| private static final Map<SingletonLocale, SingletonLocale> STRING_LOCALE_HASH_MAP = synchronizedMap(new IdentityHashMap<>()); | ||||||||||
|
Comment on lines
+22
to
+23
|
||||||||||
| private static final Map<SingletonLocale, List<SingletonLocale>> LOCALE_2_LOCALES_CHAIN = synchronizedMap(new IdentityHashMap<>()); | |
| private static final Map<SingletonLocale, SingletonLocale> STRING_LOCALE_HASH_MAP = synchronizedMap(new IdentityHashMap<>()); | |
| private static final Map<SingletonLocale, List<SingletonLocale>> LOCALE_2_LOCALES_CHAIN = new IdentityHashMap<>(); | |
| private static final Map<SingletonLocale, SingletonLocale> STRING_LOCALE_HASH_MAP = new IdentityHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRIMITIVE_WRAPPER_MAPis populated once in the static initializer and then only read. Wrapping it inCollections.synchronizedMap(...)adds unnecessary synchronization overhead; consider making it immutable instead (e.g., build theIdentityHashMapin the static block and then wrap withCollections.unmodifiableMap, or replace withMap.ofEntriesif identity semantics aren’t required).