diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index f83c5513243..959a6b4b475 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Runtime.CompilerServices; using Godot.NativeInterop; using System.Diagnostics; +using System.ComponentModel; #nullable enable @@ -83,96 +84,92 @@ namespace Godot.Collections /// Constructs a new from the given span's elements. /// /// - /// The is . + /// The is . /// /// A new Godot Array. - public Array(Span array) + public Array(scoped ReadOnlySpan span) { - if (array == null) - throw new ArgumentNullException(nameof(array)); - NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); - int length = array.Length; + int length = span.Length; Resize(length); for (int i = 0; i < length; i++) - this[i] = array[i]; + this[i] = span[i]; } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Array(scoped Span span) : this((ReadOnlySpan)span) { } + /// /// Constructs a new from the given span's elements. /// /// - /// The is . + /// The is . /// /// A new Godot Array. - public Array(Span array) + public Array(scoped ReadOnlySpan span) { - if (array == null) - throw new ArgumentNullException(nameof(array)); - NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); - int length = array.Length; + int length = span.Length; Resize(length); for (int i = 0; i < length; i++) - this[i] = array[i]; + this[i] = span[i]; } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Array(scoped Span span) : this((ReadOnlySpan)span) { } + /// /// Constructs a new from the given span's elements. /// /// - /// The is . + /// The is . /// /// A new Godot Array. - public Array(Span array) + public Array(scoped ReadOnlySpan span) { - if (array == null) - throw new ArgumentNullException(nameof(array)); - NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); - int length = array.Length; + int length = span.Length; Resize(length); for (int i = 0; i < length; i++) - this[i] = array[i]; + this[i] = span[i]; } - // We must use ReadOnlySpan instead of Span here as this can accept implicit conversions - // from derived types (e.g.: Node[]). Implicit conversion from Derived[] to Base[] are - // fine as long as the array is not mutated. However, Span does this type checking at - // instantiation, so it's not possible to use it even when not mutating anything. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Array(scoped Span span) : this((ReadOnlySpan)span) { } + /// /// Constructs a new from the given ReadOnlySpan's elements. /// /// - /// The is . + /// The is . /// /// A new Godot Array. - public Array(ReadOnlySpan array) + public Array(scoped ReadOnlySpan span) { - if (array == null) - throw new ArgumentNullException(nameof(array)); - NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); - int length = array.Length; + int length = span.Length; Resize(length); for (int i = 0; i < length; i++) - this[i] = array[i]; + this[i] = span[i]; } private Array(godot_array nativeValueToOwn)