Преглед на файлове

Actually, allow Spans to be created from null Arrays

disarray2077 преди 4 години
родител
ревизия
36c72e794e
променени са 1 файла, в които са добавени 17 реда и са изтрити 3 реда
  1. 17 3
      BeefLibs/corlib/src/Span.bf

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

@@ -16,18 +16,35 @@ namespace System
 
 
 		public this(T[] array)
 		public this(T[] array)
 		{
 		{
+			if (array == null)
+			{
+				this = default;
+				return;
+			}
 			mPtr = &array.[Friend]GetRef(0);
 			mPtr = &array.[Friend]GetRef(0);
 			mLength = array.[Friend]mLength;
 			mLength = array.[Friend]mLength;
 		}
 		}
 
 
 		public this(T[] array, int index)
 		public this(T[] array, int index)
 		{
 		{
+			if (array == null)
+			{
+				Debug.Assert(index == 0);
+				this = default;
+				return;
+			}
 			mPtr = &array[index];
 			mPtr = &array[index];
 			mLength = array.[Friend]mLength - index;
 			mLength = array.[Friend]mLength - index;
 		}
 		}
 
 
 		public this(T[] array, int index, int length)
 		public this(T[] array, int index, int length)
 		{
 		{
+			if (array == null)
+			{
+				Debug.Assert(index == 0 && length == 0);
+				this = default;
+				return;
+			}
 			if (length == 0)
 			if (length == 0)
 				mPtr = null;
 				mPtr = null;
 			else
 			else
@@ -48,9 +65,6 @@ namespace System
 
 
 		public static implicit operator Span<T> (T[] array)
 		public static implicit operator Span<T> (T[] array)
 		{
 		{
-			if (array == null)
-				return default;
-			
 			return Span<T>(array);
 			return Span<T>(array);
 		}
 		}