Avoid a few unnecessary char.ToStrings (#81980)
authorStephen Toub <stoub@microsoft.com>
Sun, 12 Feb 2023 01:29:36 +0000 (20:29 -0500)
committerGitHub <noreply@github.com>
Sun, 12 Feb 2023 01:29:36 +0000 (20:29 -0500)
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchiveEntry.Extract.cs
src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemEventArgs.cs
src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs

index f815203..4aa46fa 100644 (file)
@@ -109,7 +109,10 @@ namespace System.IO.Compression
             DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName);
             string destinationDirectoryFullPath = di.FullName;
             if (!destinationDirectoryFullPath.EndsWith(Path.DirectorySeparatorChar))
-                destinationDirectoryFullPath += Path.DirectorySeparatorChar;
+            {
+                char sep = Path.DirectorySeparatorChar;
+                destinationDirectoryFullPath = string.Concat(destinationDirectoryFullPath, new ReadOnlySpan<char>(in sep));
+            }
 
             string fileDestinationPath = Path.GetFullPath(Path.Combine(destinationDirectoryFullPath, ArchivingUtils.SanitizeEntryFilePath(source.FullName)));
 
index a83e551..4ad20be 100644 (file)
@@ -38,7 +38,7 @@ namespace System.IO
 
             return hasSeparator ?
                 directory + name :
-                directory + Path.DirectorySeparatorChar + name;
+                directory + PathInternal.DirectorySeparatorCharAsString + name;
         }
 
         /// <devdoc>
index 7577ea7..876b9e1 100644 (file)
@@ -59,7 +59,7 @@ namespace System.IO.IsolatedStorage
                 hash = IdentityHelper.GetNormalizedStrongNameHash(assemblyName)!;
                 if (hash != null)
                 {
-                    hash = "StrongName" + separator + hash;
+                    hash = string.Concat("StrongName", new ReadOnlySpan<char>(in separator), hash);
                     identity = assemblyName;
                     return;
                 }
@@ -75,7 +75,7 @@ namespace System.IO.IsolatedStorage
             if (string.IsNullOrEmpty(location))
                 throw new IsolatedStorageException(SR.IsolatedStorage_Init);
             Uri locationUri = new Uri(location);
-            hash = "Url" + separator + IdentityHelper.GetNormalizedUriHash(locationUri);
+            hash = string.Concat("Url", new ReadOnlySpan<char>(in separator), IdentityHelper.GetNormalizedUriHash(locationUri));
             identity = locationUri;
         }
 
index 5c4c8c7..597c0a0 100644 (file)
@@ -23,7 +23,9 @@ namespace System.Runtime.InteropServices
             {
                 runtimeDirectory = AppDomain.CurrentDomain.BaseDirectory;
             }
-            return Path.GetDirectoryName(runtimeDirectory) + Path.DirectorySeparatorChar;
+
+            char sep = Path.DirectorySeparatorChar;
+            return string.Concat(Path.GetDirectoryName(runtimeDirectory), new ReadOnlySpan<char>(in sep));
         }
 
         [Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]