summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
commita56e30c8d33048216567753d9d3fefc2152af8ac (patch)
tree7e5d979695fc4a431740982eb1cfecc2898b23a5 /src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
parent4b11dc566a5bbfa1378d6266525c281b028abcc8 (diff)
downloadcoreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.gz
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.bz2
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.zip
Imported Upstream version 2.0.0.11353upstream/2.0.0.11353
Diffstat (limited to 'src/mscorlib/src/System/Resources/RuntimeResourceSet.cs')
-rw-r--r--src/mscorlib/src/System/Resources/RuntimeResourceSet.cs122
1 files changed, 75 insertions, 47 deletions
diff --git a/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs b/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
index a94ac82781..e9c038a498 100644
--- a/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
+++ b/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
@@ -12,7 +12,9 @@
**
**
===========================================================*/
-namespace System.Resources {
+
+namespace System.Resources
+{
using System;
using System.IO;
using System.Collections;
@@ -162,7 +164,7 @@ namespace System.Resources {
internal sealed class RuntimeResourceSet : ResourceSet, IEnumerable
{
internal const int Version = 2; // File format version number
-
+
// Cache for resources. Key is the resource name, which can be cached
// for arbitrarily long times, since the object is usually a string
// literal that will live for the lifetime of the appdomain. The
@@ -217,11 +219,14 @@ namespace System.Resources {
{
if (Reader == null)
return;
-
- if (disposing) {
- lock(Reader) {
+
+ if (disposing)
+ {
+ lock (Reader)
+ {
_resCache = null;
- if (_defaultReader != null) {
+ if (_defaultReader != null)
+ {
_defaultReader.Close();
_defaultReader = null;
}
@@ -229,8 +234,9 @@ namespace System.Resources {
// Set Reader to null to avoid a race in GetObject.
base.Dispose(disposing);
}
- }
- else {
+ }
+ else
+ {
// Just to make sure we always clear these fields in the future...
_resCache = null;
_caseInsensitiveTable = null;
@@ -253,7 +259,7 @@ namespace System.Resources {
{
IResourceReader copyOfReader = Reader;
if (copyOfReader == null || _resCache == null)
- throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet"));
+ throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
return copyOfReader.GetEnumerator();
}
@@ -262,13 +268,13 @@ namespace System.Resources {
public override String GetString(String key)
{
Object o = GetObject(key, false, true);
- return (String) o;
+ return (String)o;
}
public override String GetString(String key, bool ignoreCase)
{
Object o = GetObject(key, ignoreCase, true);
- return (String) o;
+ return (String)o;
}
public override Object GetObject(String key)
@@ -283,34 +289,39 @@ namespace System.Resources {
private Object GetObject(String key, bool ignoreCase, bool isString)
{
- if (key==null)
+ if (key == null)
throw new ArgumentNullException(nameof(key));
if (Reader == null || _resCache == null)
- throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet"));
+ throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
Contract.EndContractBlock();
Object value = null;
ResourceLocator resLocation;
-
- lock(Reader) {
+
+ lock (Reader)
+ {
if (Reader == null)
- throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet"));
-
- if (_defaultReader != null) {
+ throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
+
+ if (_defaultReader != null)
+ {
BCLDebug.Log("RESMGRFILEFORMAT", "Going down fast path in RuntimeResourceSet::GetObject");
-
+
// Find the offset within the data section
int dataPos = -1;
- if (_resCache.TryGetValue(key, out resLocation)) {
+ if (_resCache.TryGetValue(key, out resLocation))
+ {
value = resLocation.Value;
dataPos = resLocation.DataPosition;
}
-
- if (dataPos == -1 && value == null) {
+
+ if (dataPos == -1 && value == null)
+ {
dataPos = _defaultReader.FindPosForResource(key);
}
- if (dataPos != -1 && value == null) {
+ if (dataPos != -1 && value == null)
+ {
Debug.Assert(dataPos >= 0, "data section offset cannot be negative!");
// Normally calling LoadString or LoadObject requires
// taking a lock. Note that in this case, we took a
@@ -318,28 +329,32 @@ namespace System.Resources {
// sufficient since we never pass this ResourceReader
// to anyone else.
ResourceTypeCode typeCode;
- if (isString) {
+ if (isString)
+ {
value = _defaultReader.LoadString(dataPos);
typeCode = ResourceTypeCode.String;
}
- else {
+ else
+ {
value = _defaultReader.LoadObject(dataPos, out typeCode);
}
resLocation = new ResourceLocator(dataPos, (ResourceLocator.CanCache(typeCode)) ? value : null);
- lock(_resCache) {
+ lock (_resCache)
+ {
_resCache[key] = resLocation;
}
}
-
- if (value != null || !ignoreCase) {
+
+ if (value != null || !ignoreCase)
+ {
#if LOOSELY_LINKED_RESOURCE_REFERENCE
if (Assembly != null && (value is LooselyLinkedResourceReference)) {
LooselyLinkedResourceReference assRef = (LooselyLinkedResourceReference) value;
value = assRef.Resolve(Assembly);
}
#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
-
+
return value; // may be null
}
} // if (_defaultReader != null)
@@ -347,20 +362,24 @@ namespace System.Resources {
// At this point, we either don't have our default resource reader
// or we haven't found the particular resource we're looking for
// and may have to search for it in a case-insensitive way.
- if (!_haveReadFromReader) {
+ if (!_haveReadFromReader)
+ {
// If necessary, init our case insensitive hash table.
- if (ignoreCase && _caseInsensitiveTable == null) {
+ if (ignoreCase && _caseInsensitiveTable == null)
+ {
_caseInsensitiveTable = new Dictionary<String, ResourceLocator>(StringComparer.OrdinalIgnoreCase);
}
#if _DEBUG
- BCLDebug.Perf(!ignoreCase, "Using case-insensitive lookups is bad perf-wise. Consider capitalizing "+key+" correctly in your source");
+ BCLDebug.Perf(!ignoreCase, "Using case-insensitive lookups is bad perf-wise. Consider capitalizing " + key + " correctly in your source");
#endif
- if (_defaultReader == null) {
+ if (_defaultReader == null)
+ {
IDictionaryEnumerator en = Reader.GetEnumerator();
- while (en.MoveNext()) {
+ while (en.MoveNext())
+ {
DictionaryEntry entry = en.Entry;
- String readKey = (String) entry.Key;
+ String readKey = (String)entry.Key;
ResourceLocator resLoc = new ResourceLocator(-1, entry.Value);
_resCache.Add(readKey, resLoc);
if (ignoreCase)
@@ -371,12 +390,14 @@ namespace System.Resources {
if (!ignoreCase)
Reader.Close();
}
- else {
+ else
+ {
Debug.Assert(ignoreCase, "This should only happen for case-insensitive lookups");
ResourceReader.ResourceEnumerator en = _defaultReader.GetEnumeratorInternal();
- while (en.MoveNext()) {
+ while (en.MoveNext())
+ {
// Note: Always ask for the resource key before the data position.
- String currentKey = (String) en.Key;
+ String currentKey = (String)en.Key;
int dataPos = en.DataPosition;
ResourceLocator resLoc = new ResourceLocator(dataPos, null);
_caseInsensitiveTable.Add(currentKey, resLoc);
@@ -387,19 +408,23 @@ namespace System.Resources {
Object obj = null;
bool found = false;
bool keyInWrongCase = false;
- if (_defaultReader != null) {
- if (_resCache.TryGetValue(key, out resLocation)) {
+ if (_defaultReader != null)
+ {
+ if (_resCache.TryGetValue(key, out resLocation))
+ {
found = true;
- obj = ResolveResourceLocator(resLocation, key, _resCache, keyInWrongCase);
+ obj = ResolveResourceLocator(resLocation, key, _resCache, keyInWrongCase);
}
}
- if (!found && ignoreCase) {
- if (_caseInsensitiveTable.TryGetValue(key, out resLocation)) {
+ if (!found && ignoreCase)
+ {
+ if (_caseInsensitiveTable.TryGetValue(key, out resLocation))
+ {
found = true;
keyInWrongCase = true;
obj = ResolveResourceLocator(resLocation, key, _resCache, keyInWrongCase);
}
- }
+ }
return obj;
} // lock(Reader)
}
@@ -412,12 +437,15 @@ namespace System.Resources {
// We need to explicitly resolve loosely linked manifest
// resources, and we need to resolve ResourceLocators with null objects.
Object value = resLocation.Value;
- if (value == null) {
+ if (value == null)
+ {
ResourceTypeCode typeCode;
- lock(Reader) {
+ lock (Reader)
+ {
value = _defaultReader.LoadObject(resLocation.DataPosition, out typeCode);
}
- if (!keyInWrongCase && ResourceLocator.CanCache(typeCode)) {
+ if (!keyInWrongCase && ResourceLocator.CanCache(typeCode))
+ {
resLocation.Value = value;
copyOfCache[key] = resLocation;
}