Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 56737cd

Browse files
Reduce lock contentions in GetCultureInfoHelper (#28202)
1 parent 99d81d2 commit 56737cd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,10 @@ internal bool HasInvariantCultureName
11421142
{
11431143
Debug.Assert(name != null && (lcid != -1 || altName != null));
11441144
bool ret;
1145+
string key = lcid == 0 ? name! : name! + '\xfffd' + altName!;
11451146
lock (_lock)
11461147
{
1147-
ret = tempNameHT.TryGetValue(lcid == 0 ? name! : name! + '\xfffd' + altName!, out retval);
1148+
ret = tempNameHT.TryGetValue(key, out retval);
11481149
}
11491150

11501151
if (ret && retval != null)
@@ -1211,10 +1212,11 @@ internal bool HasInvariantCultureName
12111212

12121213
if (lcid == -1)
12131214
{
1215+
string key = name + '\xfffd' + altName;
12141216
lock (_lock)
12151217
{
12161218
// This new culture will be added only to the name hash table.
1217-
tempNameHT[name + '\xfffd' + altName] = retval;
1219+
tempNameHT[key] = retval;
12181220
}
12191221
// when lcid == -1 then TextInfo object is already get created and we need to set it as read only.
12201222
retval.TextInfo.SetReadOnlyState(true);

0 commit comments

Comments
 (0)