Skip to content

Commit c14fbc9

Browse files
angularsenlipchev
andauthored
🐛 Fix concurrency issue when getting abbreviations (#1159)
Fixes #919 Duplicates #924 Do not update collection on get. Co-authored-by: lipchev <[email protected]>
1 parent f648994 commit c14fbc9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

UnitsNet/CustomCode/UnitValueAbbreviationLookup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal List<string> GetAbbreviationsForUnit<TUnitType>(TUnitType unit) where T
2929
internal List<string> GetAbbreviationsForUnit(int unit)
3030
{
3131
if (!_unitToAbbreviationMap.TryGetValue(unit, out var abbreviations))
32-
_unitToAbbreviationMap[unit] = abbreviations = new List<string>();
32+
return new List<string>(0);
3333

3434
return abbreviations.Distinct().ToList();
3535
}
@@ -41,7 +41,7 @@ internal List<int> GetUnitsForAbbreviation(string abbreviation, bool ignoreCase)
4141
var map = ignoreCase ? _lowerCaseAbbreviationToUnitMap : _abbreviationToUnitMap;
4242

4343
if (!map.TryGetValue(key, out List<int> units))
44-
map[key] = units = new List<int>();
44+
return new List<int>(0);
4545

4646
return units.Distinct().ToList();
4747
}

0 commit comments

Comments
 (0)