Skip to content

Commit 30a0163

Browse files
refactor: Remove misleading SplitToEnumerableNoAlloc and SplitAsMemoryNoAlloc
These methods called .ToString()/.AsMemory() per segment, allocating memory and making the 'NoAlloc' naming misleading. Users wanting strings should use BCL Split() or explicitly call .Select(s => s.ToString()) to make allocations visible. The true zero-allocation methods (SplitAsSegmentsNoAlloc returning StringSegment) remain unchanged.
1 parent d8560ab commit 30a0163

2 files changed

Lines changed: 0 additions & 95 deletions

File tree

Source/Extensions.Split.NoAlloc.cs

Lines changed: 0 additions & 85 deletions
This file was deleted.

Tests/SplitTests.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public static void ThrowIfNull()
5252
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitAsSegments(","));
5353
Assert.Throws<ArgumentNullException>(() => DefaultTestString.SplitAsSegments(default(string)!));
5454
// NoAlloc variants
55-
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitToEnumerableNoAlloc(','));
56-
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitToEnumerableNoAlloc(","));
57-
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitAsMemoryNoAlloc(','));
58-
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitAsMemoryNoAlloc(","));
5955
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitAsSegmentsNoAlloc(','));
6056
Assert.Throws<ArgumentNullException>(() => default(string)!.SplitAsSegmentsNoAlloc(","));
6157
Assert.Throws<ArgumentNullException>(() => DefaultTestString.SplitAsSegmentsNoAlloc(default(string)!));
@@ -116,10 +112,6 @@ public static void Split(string sequence, StringSplitOptions options = StringSpl
116112
Assert.Equal(segments, sequence.SplitAsSegments(",", options: options).Select(m => m.ToString()).ToArray());
117113
Assert.Equal(segments, sequence.SplitAsSegments(new Regex(","), options: options).Select(m => m.ToString()).ToArray());
118114
// NoAlloc variants - should produce identical results
119-
Assert.Equal(segments, sequence.SplitToEnumerableNoAlloc(',', options).ToArray());
120-
Assert.Equal(segments, sequence.SplitToEnumerableNoAlloc(",", options: options).ToArray());
121-
Assert.Equal(segments, sequence.SplitAsMemoryNoAlloc(',', options).Select(m => m.Span.ToString()).ToArray());
122-
Assert.Equal(segments, sequence.SplitAsMemoryNoAlloc(",", options: options).Select(m => m.Span.ToString()).ToArray());
123115
Assert.Equal(segments, sequence.SplitAsSegmentsNoAlloc(',', options).Select(m => m.ToString()).ToArray());
124116
Assert.Equal(segments, sequence.SplitAsSegmentsNoAlloc(",", options: options).Select(m => m.ToString()).ToArray());
125117
Assert.Equal(segments, sequence.SplitAsSegmentsNoAlloc(new Regex(","), options: options).Select(m => m.ToString()).ToArray());
@@ -167,8 +159,6 @@ public static void SplitIgnoreCase(string sequence, string split, string expecte
167159
Assert.Equal(segments, sequence.SplitAsMemory(split, options, StringComparison.OrdinalIgnoreCase).Select(m => m.Span.ToString()));
168160
Assert.Equal(segments, sequence.SplitAsSegments(split, options, StringComparison.OrdinalIgnoreCase).Select(m => m.ToString()));
169161
// NoAlloc variants
170-
Assert.Equal(segments, sequence.SplitToEnumerableNoAlloc(split, options, StringComparison.OrdinalIgnoreCase).ToArray());
171-
Assert.Equal(segments, sequence.SplitAsMemoryNoAlloc(split, options, StringComparison.OrdinalIgnoreCase).Select(m => m.Span.ToString()).ToArray());
172162
Assert.Equal(segments, sequence.SplitAsSegmentsNoAlloc(split, options, StringComparison.OrdinalIgnoreCase).Select(m => m.ToString()).ToArray());
173163
var span = sequence.AsSpan();
174164
Assert.Equal(segments, span.Split(split, options, StringComparison.OrdinalIgnoreCase));

0 commit comments

Comments
 (0)