Skip to content

Commit f81cf4b

Browse files
committed
Switch to target-type new() for direct return values
1 parent 57f4c3d commit f81cf4b

File tree

25 files changed

+78
-78
lines changed

25 files changed

+78
-78
lines changed

CommunityToolkit.Diagnostics/Extensions/ValueTypeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public static unsafe string ToHexString<T>(this T value)
6363
p[j] = (char)Unsafe.Add(ref rh, high);
6464
}
6565

66-
return new string(p, 0, bufferSize);
66+
return new(p, 0, bufferSize);
6767
}
6868
}

CommunityToolkit.HighPerformance/Buffers/ArrayPoolBufferWriter{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public override string ToString()
325325
if (typeof(T) == typeof(char) &&
326326
this.array is char[] chars)
327327
{
328-
return new string(chars, 0, this.index);
328+
return new(chars, 0, this.index);
329329
}
330330

331331
// Same representation used in Span<T>

CommunityToolkit.HighPerformance/Buffers/Internals/ArrayMemoryManager{TFrom,TTo}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public override unsafe MemoryHandle Pin(int elementIndex = 0)
8686
ref byte r2 = ref Unsafe.Add(ref r1, byteOffset);
8787
void* pi = Unsafe.AsPointer(ref r2);
8888

89-
return new MemoryHandle(pi, handle);
89+
return new(pi, handle);
9090
}
9191

9292
/// <inheritdoc/>

CommunityToolkit.HighPerformance/Buffers/Internals/RawObjectMemoryManager{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override unsafe MemoryHandle Pin(int elementIndex = 0)
7272
ref T r1 = ref Unsafe.Add(ref r0, (nint)(uint)elementIndex);
7373
void* p = Unsafe.AsPointer(ref r1);
7474

75-
return new MemoryHandle(p, handle);
75+
return new(p, handle);
7676
}
7777

7878
/// <inheritdoc/>

CommunityToolkit.HighPerformance/Buffers/Internals/StringMemoryManager{TTo}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override unsafe MemoryHandle Pin(int elementIndex = 0)
8282
ref byte r2 = ref Unsafe.Add(ref r1, byteOffset);
8383
void* pi = Unsafe.AsPointer(ref r2);
8484

85-
return new MemoryHandle(pi, handle);
85+
return new(pi, handle);
8686
}
8787

8888
/// <inheritdoc/>

CommunityToolkit.HighPerformance/Buffers/MemoryOwner{T}.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public Memory<T> Memory
157157
ThrowObjectDisposedException();
158158
}
159159

160-
return new Memory<T>(array!, this.start, this.length);
160+
return new(array!, this.start, this.length);
161161
}
162162
}
163163

@@ -190,7 +190,7 @@ public Span<T> Span
190190
// especially if T is a value type, in which case the covariance check is JIT removed.
191191
return MemoryMarshal.CreateSpan(ref r0, this.length);
192192
#else
193-
return new Span<T>(array!, this.start, this.length);
193+
return new(array!, this.start, this.length);
194194
#endif
195195
}
196196
}
@@ -239,7 +239,7 @@ public ArraySegment<T> DangerousGetArray()
239239
ThrowObjectDisposedException();
240240
}
241241

242-
return new ArraySegment<T>(array!, this.start, this.length);
242+
return new(array!, this.start, this.length);
243243
}
244244

245245
/// <summary>
@@ -282,7 +282,7 @@ public MemoryOwner<T> Slice(int start, int length)
282282
// suppress the finalizer to reduce the overhead on the garbage collector.
283283
GC.SuppressFinalize(this);
284284

285-
return new MemoryOwner<T>(start, length, this.pool, array!);
285+
return new(start, length, this.pool, array!);
286286
}
287287

288288
/// <inheritdoc/>
@@ -312,7 +312,7 @@ public override string ToString()
312312
if (typeof(T) == typeof(char) &&
313313
this.array is char[] chars)
314314
{
315-
return new string(chars, this.start, this.length);
315+
return new(chars, this.start, this.length);
316316
}
317317

318318
// Same representation used in Span<T>

CommunityToolkit.HighPerformance/Buffers/SpanOwner{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public Span<T> Span
146146

147147
return MemoryMarshal.CreateSpan(ref r0, this.length);
148148
#else
149-
return new Span<T>(this.array, 0, this.length);
149+
return new(this.array, 0, this.length);
150150
#endif
151151
}
152152
}
@@ -192,7 +192,7 @@ public override string ToString()
192192
if (typeof(T) == typeof(char) &&
193193
this.array is char[] chars)
194194
{
195-
return new string(chars, 0, this.length);
195+
return new(chars, 0, this.length);
196196
}
197197

198198
// Same representation used in Span<T>

CommunityToolkit.HighPerformance/Enumerables/ReadOnlyRefEnumerable{T}.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static ReadOnlyRefEnumerable<T> DangerousCreate(in T value, int length, i
9898

9999
OverflowHelper.EnsureIsInNativeIntRange(length, 1, step);
100100

101-
return new ReadOnlyRefEnumerable<T>(in value, length, step);
101+
return new(in value, length, step);
102102
}
103103
#else
104104
/// <summary>
@@ -182,9 +182,9 @@ public ref readonly T this[Index index]
182182
public Enumerator GetEnumerator()
183183
{
184184
#if NETSTANDARD2_1_OR_GREATER
185-
return new Enumerator(this.span, this.step);
185+
return new(this.span, this.step);
186186
#else
187-
return new Enumerator(this.instance, this.offset, this.length, this.step);
187+
return new(this.instance, this.offset, this.length, this.step);
188188
#endif
189189
}
190190

@@ -342,9 +342,9 @@ public T[] ToArray()
342342
public static implicit operator ReadOnlyRefEnumerable<T>(RefEnumerable<T> enumerable)
343343
{
344344
#if NETSTANDARD2_1_OR_GREATER
345-
return new ReadOnlyRefEnumerable<T>(enumerable.Span, enumerable.Step);
345+
return new(enumerable.Span, enumerable.Step);
346346
#else
347-
return new ReadOnlyRefEnumerable<T>(enumerable.Instance, enumerable.Offset, enumerable.Length, enumerable.Step);
347+
return new(enumerable.Instance, enumerable.Offset, enumerable.Length, enumerable.Step);
348348
#endif
349349
}
350350

CommunityToolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public readonly Item Current
6868
ref T ri = ref Unsafe.Add(ref r0, (nint)(uint)this.index);
6969

7070
// See comment in SpanEnumerable<T> about this
71-
return new Item(ref ri, this.index);
71+
return new(ref ri, this.index);
7272
#else
73-
return new Item(this.span, this.index);
73+
return new(this.span, this.index);
7474
#endif
7575
}
7676
}

CommunityToolkit.HighPerformance/Enumerables/RefEnumerable{T}.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static RefEnumerable<T> DangerousCreate(ref T value, int length, int step
8181

8282
OverflowHelper.EnsureIsInNativeIntRange(length, 1, step);
8383

84-
return new RefEnumerable<T>(ref value, length, step);
84+
return new(ref value, length, step);
8585
}
8686
#else
8787
/// <summary>
@@ -165,9 +165,9 @@ public ref T this[Index index]
165165
public Enumerator GetEnumerator()
166166
{
167167
#if NETSTANDARD2_1_OR_GREATER
168-
return new Enumerator(this.Span, this.Step);
168+
return new(this.Span, this.Step);
169169
#else
170-
return new Enumerator(this.Instance, this.Offset, this.Length, this.Step);
170+
return new(this.Instance, this.Offset, this.Length, this.Step);
171171
#endif
172172
}
173173

0 commit comments

Comments
 (0)