From a49799e916b8f54f32f04cf9868cd34ddffabd2f Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 16 Jan 2019 09:07:53 -0500 Subject: [PATCH 1/2] Remove ToString from RuntimeAssembly.GetManifestResourceStream A small allocation we can avoid with the span-based string.Concat. --- .../src/System/Reflection/RuntimeAssembly.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 45d73a65bfa4..28d7fc9023c2 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -207,8 +207,11 @@ public override Stream GetManifestResourceStream(Type type, string name) throw new ArgumentNullException(nameof(type)); string nameSpace = type?.Namespace; - string delimiter = (nameSpace != null && name != null) ? Type.Delimiter.ToString() : null; - string resourceName = string.Concat(nameSpace, delimiter, name); + + char c = Type.Delimiter; + string resourceName = nameSpace != null && name != null ? + string.Concat(nameSpace, new Span(ref c, 1), name) : + string.Concat(nameSpace, name); return GetManifestResourceStream(resourceName); } From ebece7e607aaee77deff601d8a88a6103b7b0a6b Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 17 Jan 2019 11:47:40 -0500 Subject: [PATCH 2/2] Address PR feedback --- .../src/System/Reflection/RuntimeAssembly.cs | 2 +- .../src/System/Resources/ManifestBasedResourceGroveler.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 28d7fc9023c2..3035117b9e53 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -210,7 +210,7 @@ public override Stream GetManifestResourceStream(Type type, string name) char c = Type.Delimiter; string resourceName = nameSpace != null && name != null ? - string.Concat(nameSpace, new Span(ref c, 1), name) : + string.Concat(nameSpace, new ReadOnlySpan(ref c, 1), name) : string.Concat(nameSpace, name); return GetManifestResourceStream(resourceName); diff --git a/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs b/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs index fe95bf1c8f68..42b601336a55 100644 --- a/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs +++ b/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs @@ -330,8 +330,11 @@ private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satel Debug.Assert(name != null, "name shouldn't be null; check caller"); string nameSpace = _mediator.LocationInfo?.Namespace; - string delimiter = (nameSpace != null && name != null) ? Type.Delimiter.ToString() : null; - string resourceName = string.Concat(nameSpace, delimiter, name); + + char c = Type.Delimiter; + string resourceName = nameSpace != null && name != null ? + string.Concat(nameSpace, new ReadOnlySpan(ref c, 1), name) : + string.Concat(nameSpace, name); string canonicalName = null; foreach (string existingName in satellite.GetManifestResourceNames())