Remove faulty asserts from ArraySegment (dotnet/coreclr#10086)
authorStephen Toub <stoub@microsoft.com>
Fri, 10 Mar 2017 14:28:15 +0000 (09:28 -0500)
committerJan Kotas <jkotas@microsoft.com>
Fri, 10 Mar 2017 14:28:15 +0000 (06:28 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/d908ed6640eac4d42dd67f21164ced3df0b2b51f

src/coreclr/src/mscorlib/src/System/ArraySegment.cs

index fa02938..1e127e3 100644 (file)
@@ -56,55 +56,11 @@ namespace System
             _count = count;
         }
 
-        public T[] Array
-        {
-            get
-            {
-                Debug.Assert((null == _array && 0 == _offset && 0 == _count)
-                                 || (null != _array && _offset >= 0 && _count >= 0 && _offset + _count <= _array.Length),
-                                "ArraySegment is invalid");
-
-                return _array;
-            }
-        }
+        public T[] Array => _array;
 
-        public int Offset
-        {
-            get
-            {
-                // Since copying value types is not atomic & callers cannot atomically 
-                // read all three fields, we cannot guarantee that Offset is within 
-                // the bounds of Array.  That is our intent, but let's not specify 
-                // it as a postcondition - force callers to re-verify this themselves
-                // after reading each field out of an ArraySegment into their stack.
-                Contract.Ensures(Contract.Result<int>() >= 0);
-
-                Debug.Assert((null == _array && 0 == _offset && 0 == _count)
-                                 || (null != _array && _offset >= 0 && _count >= 0 && _offset + _count <= _array.Length),
-                                "ArraySegment is invalid");
-
-                return _offset;
-            }
-        }
+        public int Offset => _offset;
 
-        public int Count
-        {
-            get
-            {
-                // Since copying value types is not atomic & callers cannot atomically 
-                // read all three fields, we cannot guarantee that Count is within 
-                // the bounds of Array.  That's our intent, but let's not specify 
-                // it as a postcondition - force callers to re-verify this themselves
-                // after reading each field out of an ArraySegment into their stack.
-                Contract.Ensures(Contract.Result<int>() >= 0);
-
-                Debug.Assert((null == _array && 0 == _offset && 0 == _count)
-                                  || (null != _array && _offset >= 0 && _count >= 0 && _offset + _count <= _array.Length),
-                                "ArraySegment is invalid");
-
-                return _count;
-            }
-        }
+        public int Count => _count;
 
         public Enumerator GetEnumerator()
         {