|
6 | 6 | using System.Runtime.CompilerServices; |
7 | 7 | using Godot.NativeInterop; |
8 | 8 | using System.Diagnostics; |
| 9 | +using System.ComponentModel; |
9 | 10 |
|
10 | 11 | #nullable enable |
11 | 12 |
|
@@ -83,96 +84,92 @@ public Array(Variant[] array) |
83 | 84 | /// Constructs a new <see cref="Array"/> from the given span's elements. |
84 | 85 | /// </summary> |
85 | 86 | /// <exception cref="ArgumentNullException"> |
86 | | - /// The <paramref name="array"/> is <see langword="null"/>. |
| 87 | + /// The <paramref name="span"/> is <see langword="null"/>. |
87 | 88 | /// </exception> |
88 | 89 | /// <returns>A new Godot Array.</returns> |
89 | | - public Array(Span<StringName> array) |
| 90 | + public Array(scoped ReadOnlySpan<StringName> span) |
90 | 91 | { |
91 | | - if (array == null) |
92 | | - throw new ArgumentNullException(nameof(array)); |
93 | | - |
94 | 92 | NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); |
95 | 93 | _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); |
96 | 94 |
|
97 | | - int length = array.Length; |
| 95 | + int length = span.Length; |
98 | 96 |
|
99 | 97 | Resize(length); |
100 | 98 |
|
101 | 99 | for (int i = 0; i < length; i++) |
102 | | - this[i] = array[i]; |
| 100 | + this[i] = span[i]; |
103 | 101 | } |
104 | 102 |
|
| 103 | + /// <inheritdoc cref="Array(ReadOnlySpan{StringName})"/> |
| 104 | + [EditorBrowsable(EditorBrowsableState.Never)] |
| 105 | + public Array(scoped Span<StringName> span) : this((ReadOnlySpan<StringName>)span) { } |
| 106 | + |
105 | 107 | /// <summary> |
106 | 108 | /// Constructs a new <see cref="Array"/> from the given span's elements. |
107 | 109 | /// </summary> |
108 | 110 | /// <exception cref="ArgumentNullException"> |
109 | | - /// The <paramref name="array"/> is <see langword="null"/>. |
| 111 | + /// The <paramref name="span"/> is <see langword="null"/>. |
110 | 112 | /// </exception> |
111 | 113 | /// <returns>A new Godot Array.</returns> |
112 | | - public Array(Span<NodePath> array) |
| 114 | + public Array(scoped ReadOnlySpan<NodePath> span) |
113 | 115 | { |
114 | | - if (array == null) |
115 | | - throw new ArgumentNullException(nameof(array)); |
116 | | - |
117 | 116 | NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); |
118 | 117 | _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); |
119 | 118 |
|
120 | | - int length = array.Length; |
| 119 | + int length = span.Length; |
121 | 120 |
|
122 | 121 | Resize(length); |
123 | 122 |
|
124 | 123 | for (int i = 0; i < length; i++) |
125 | | - this[i] = array[i]; |
| 124 | + this[i] = span[i]; |
126 | 125 | } |
127 | 126 |
|
| 127 | + /// <inheritdoc cref="Array(ReadOnlySpan{NodePath})"/> |
| 128 | + [EditorBrowsable(EditorBrowsableState.Never)] |
| 129 | + public Array(scoped Span<NodePath> span) : this((ReadOnlySpan<NodePath>)span) { } |
| 130 | + |
128 | 131 | /// <summary> |
129 | 132 | /// Constructs a new <see cref="Array"/> from the given span's elements. |
130 | 133 | /// </summary> |
131 | 134 | /// <exception cref="ArgumentNullException"> |
132 | | - /// The <paramref name="array"/> is <see langword="null"/>. |
| 135 | + /// The <paramref name="span"/> is <see langword="null"/>. |
133 | 136 | /// </exception> |
134 | 137 | /// <returns>A new Godot Array.</returns> |
135 | | - public Array(Span<Rid> array) |
| 138 | + public Array(scoped ReadOnlySpan<Rid> span) |
136 | 139 | { |
137 | | - if (array == null) |
138 | | - throw new ArgumentNullException(nameof(array)); |
139 | | - |
140 | 140 | NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); |
141 | 141 | _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); |
142 | 142 |
|
143 | | - int length = array.Length; |
| 143 | + int length = span.Length; |
144 | 144 |
|
145 | 145 | Resize(length); |
146 | 146 |
|
147 | 147 | for (int i = 0; i < length; i++) |
148 | | - this[i] = array[i]; |
| 148 | + this[i] = span[i]; |
149 | 149 | } |
150 | 150 |
|
151 | | - // We must use ReadOnlySpan instead of Span here as this can accept implicit conversions |
152 | | - // from derived types (e.g.: Node[]). Implicit conversion from Derived[] to Base[] are |
153 | | - // fine as long as the array is not mutated. However, Span does this type checking at |
154 | | - // instantiation, so it's not possible to use it even when not mutating anything. |
| 151 | + /// <inheritdoc cref="Array(ReadOnlySpan{Rid})"/> |
| 152 | + [EditorBrowsable(EditorBrowsableState.Never)] |
| 153 | + public Array(scoped Span<Rid> span) : this((ReadOnlySpan<Rid>)span) { } |
| 154 | + |
155 | 155 | /// <summary> |
156 | 156 | /// Constructs a new <see cref="Array"/> from the given ReadOnlySpan's elements. |
157 | 157 | /// </summary> |
158 | 158 | /// <exception cref="ArgumentNullException"> |
159 | | - /// The <paramref name="array"/> is <see langword="null"/>. |
| 159 | + /// The <paramref name="span"/> is <see langword="null"/>. |
160 | 160 | /// </exception> |
161 | 161 | /// <returns>A new Godot Array.</returns> |
162 | | - public Array(ReadOnlySpan<GodotObject> array) |
| 162 | + public Array(scoped ReadOnlySpan<GodotObject> span) |
163 | 163 | { |
164 | | - if (array == null) |
165 | | - throw new ArgumentNullException(nameof(array)); |
166 | | - |
167 | 164 | NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new(); |
168 | 165 | _weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this); |
169 | 166 |
|
170 | | - int length = array.Length; |
| 167 | + int length = span.Length; |
171 | 168 |
|
172 | 169 | Resize(length); |
173 | 170 |
|
174 | 171 | for (int i = 0; i < length; i++) |
175 | | - this[i] = array[i]; |
| 172 | + this[i] = span[i]; |
176 | 173 | } |
177 | 174 |
|
178 | 175 | private Array(godot_array nativeValueToOwn) |
|
0 commit comments