Align ArrayPool to shared code pattern
authorJeremy Kuhne <jeremy.kuhne@microsoft.com>
Fri, 28 Oct 2016 21:56:24 +0000 (14:56 -0700)
committerJeremy Kuhne <jeremy.kuhne@microsoft.com>
Fri, 28 Oct 2016 21:56:24 +0000 (14:56 -0700)
Move the ArrayPool code to the shared location. Also use wraps to make
code identical to CoreFX. (Fixing an exception message issue.)

Commit migrated from https://github.com/dotnet/coreclr/commit/6a7f5ead07e244e89df5602a4d5d477aa1f14b4b

src/coreclr/src/mscorlib/corefx/SR.cs
src/coreclr/src/mscorlib/corefx/System/Buffers/ArrayPool.cs [moved from src/coreclr/src/mscorlib/src/System/Buffers/ArrayPool.cs with 100% similarity]
src/coreclr/src/mscorlib/corefx/System/Buffers/ArrayPoolEventSource.cs [moved from src/coreclr/src/mscorlib/src/System/Buffers/ArrayPoolEventSource.cs with 100% similarity]
src/coreclr/src/mscorlib/corefx/System/Buffers/DefaultArrayPool.cs [moved from src/coreclr/src/mscorlib/src/System/Buffers/DefaultArrayPool.cs with 100% similarity]
src/coreclr/src/mscorlib/corefx/System/Buffers/DefaultArrayPoolBucket.cs [moved from src/coreclr/src/mscorlib/src/System/Buffers/DefaultArrayPoolBucket.cs with 97% similarity]
src/coreclr/src/mscorlib/corefx/System/Buffers/Utilities.cs [moved from src/coreclr/src/mscorlib/src/System/Buffers/Utilities.cs with 91% similarity]
src/coreclr/src/mscorlib/mscorlib.shared.sources.props

index e49561b..e69d6b2 100644 (file)
@@ -495,6 +495,11 @@ namespace System
             get { return Environment.GetResourceString("InvalidOperation_NativeOverlappedReused"); }
         }
 
+        public static string ArgumentException_BufferNotFromPool
+        {
+            get { return Environment.GetResourceString("ArgumentException_BufferNotFromPool"); }
+        }
+
         public static string Format(string formatString, params object[] args)
         {
             return string.Format(CultureInfo.CurrentCulture, formatString, args);
@@ -88,7 +88,7 @@ namespace System.Buffers
                 // Check to see if the buffer is the correct size for this bucket
                 if (array.Length != _bufferLength)
                 {
-                    throw new ArgumentException(Environment.GetResourceString("ArgumentException_BufferNotFromPool", nameof(array)));
+                    throw new ArgumentException(SR.ArgumentException_BufferNotFromPool, nameof(array));
                 }
 
                 // While holding the spin lock, if there's room available in the bucket,
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+using System.Diagnostics;
 using System.Runtime.CompilerServices;
 
 namespace System.Buffers
@@ -11,7 +12,7 @@ namespace System.Buffers
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         internal static int SelectBucketIndex(int bufferSize)
         {
-            BCLDebug.Assert(bufferSize > 0);
+            Debug.Assert(bufferSize > 0);
 
             uint bitsRemaining = ((uint)bufferSize - 1) >> 4;
 
@@ -29,7 +30,7 @@ namespace System.Buffers
         internal static int GetMaxSizeForBucket(int binIndex)
         {
             int maxSize = 16 << binIndex;
-            BCLDebug.Assert(maxSize >= 0);
+            Debug.Assert(maxSize >= 0);
             return maxSize;
         }
     }
index 6df32ba..3d171c5 100644 (file)
   <ItemGroup>
     <NumericsSources Include="$(BclSourcesRoot)\System\Numerics\Hashing\HashHelpers.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <BuffersSources Condition="'$(FeatureCoreClr)'=='true'" Include="$(BclSourcesRoot)\System\Buffers\ArrayPool.cs" />
-    <BuffersSources Condition="'$(FeatureCoreClr)'=='true'" Include="$(BclSourcesRoot)\System\Buffers\ArrayPoolEventSource.cs" />
-    <BuffersSources Condition="'$(FeatureCoreClr)'=='true'" Include="$(BclSourcesRoot)\System\Buffers\DefaultArrayPool.cs" />
-    <BuffersSources Condition="'$(FeatureCoreClr)'=='true'" Include="$(BclSourcesRoot)\System\Buffers\DefaultArrayPoolBucket.cs" />
-    <BuffersSources Condition="'$(FeatureCoreClr)'=='true'" Include="$(BclSourcesRoot)\System\Buffers\Utilities.cs" />
+  <ItemGroup Condition="'$(FeatureCoreClr)'=='true'">
+    <BuffersSources Include="$(CoreFxSourcesRoot)\System\Buffers\ArrayPool.cs" />
+    <BuffersSources Include="$(CoreFxSourcesRoot)\System\Buffers\ArrayPoolEventSource.cs" />
+    <BuffersSources Include="$(CoreFxSourcesRoot)\System\Buffers\DefaultArrayPool.cs" />
+    <BuffersSources Include="$(CoreFxSourcesRoot)\System\Buffers\DefaultArrayPoolBucket.cs" />
+    <BuffersSources Include="$(CoreFxSourcesRoot)\System\Buffers\Utilities.cs" />
   </ItemGroup>
   <ItemGroup Condition="'$(FeatureCoreFxWindowsInterop)' == 'true'">
     <WindowsInteropSources Include="$(CoreFxSourcesRoot)\System\HResults.cs" />