浏览代码

Merge pull request #1082 from disarray2077/null_array_span

Allow Spans to be created from null Arrays
Brian Fiete 4 年之前
父节点
当前提交
b66f13849f
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17 0
      BeefLibs/corlib/src/Span.bf

+ 17 - 0
BeefLibs/corlib/src/Span.bf

@@ -16,18 +16,35 @@ namespace System
 
 		public this(T[] array)
 		{
+			if (array == null)
+			{
+				this = default;
+				return;
+			}
 			mPtr = &array.[Friend]GetRef(0);
 			mLength = array.[Friend]mLength;
 		}
 
 		public this(T[] array, int index)
 		{
+			if (array == null)
+			{
+				Debug.Assert(index == 0);
+				this = default;
+				return;
+			}
 			mPtr = &array[index];
 			mLength = array.[Friend]mLength - index;
 		}
 
 		public this(T[] array, int index, int length)
 		{
+			if (array == null)
+			{
+				Debug.Assert(index == 0 && length == 0);
+				this = default;
+				return;
+			}
 			if (length == 0)
 				mPtr = null;
 			else