From 056260c59c6a91d9dad71e33ef72b58746bb83ba Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 10 Mar 2017 09:28:15 -0500 Subject: [PATCH] Remove faulty asserts from ArraySegment (dotnet/coreclr#10086) Commit migrated from https://github.com/dotnet/coreclr/commit/d908ed6640eac4d42dd67f21164ced3df0b2b51f --- .../src/mscorlib/src/System/ArraySegment.cs | 50 ++-------------------- 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/ArraySegment.cs b/src/coreclr/src/mscorlib/src/System/ArraySegment.cs index fa02938..1e127e3 100644 --- a/src/coreclr/src/mscorlib/src/System/ArraySegment.cs +++ b/src/coreclr/src/mscorlib/src/System/ArraySegment.cs @@ -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() >= 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() >= 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() { -- 2.7.4