Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/mscorlib/src/System/Resources/ResourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,22 +1373,24 @@ public DictionaryEntry Entry {

String key;
Object value = null;
lock (_reader._resCache) {
key = _reader.AllocateStringForNameIndex(_currentName, out _dataPosition);
ResourceLocator locator;
if (_reader._resCache.TryGetValue(key, out locator)) {
value = locator.Value;
}
if (value == null) {
if (_dataPosition == -1)
value = _reader.GetValueForNameIndex(_currentName);
else
value = _reader.LoadObject(_dataPosition);
// If enumeration and subsequent lookups happen very
// frequently in the same process, add a ResourceLocator
// to _resCache here. But WinForms enumerates and
// just about everyone else does lookups. So caching
// here may bloat working set.
lock (_reader) { // locks should be taken in the same order as in RuntimeResourceSet.GetObject to avoid deadlock
lock (_reader._resCache) {
key = _reader.AllocateStringForNameIndex(_currentName, out _dataPosition); // AllocateStringForNameIndex could lock on _reader
ResourceLocator locator;
if (_reader._resCache.TryGetValue(key, out locator)) {
value = locator.Value;
}
if (value == null) {
if (_dataPosition == -1)
value = _reader.GetValueForNameIndex(_currentName);
else
value = _reader.LoadObject(_dataPosition);
// If enumeration and subsequent lookups happen very
// frequently in the same process, add a ResourceLocator
// to _resCache here. But WinForms enumerates and
// just about everyone else does lookups. So caching
// here may bloat working set.
}
}
}
return new DictionaryEntry(key, value);
Expand Down