Skip to content

Commit 6bf79a2

Browse files
committed
more fixes
1 parent 4e66a7b commit 6bf79a2

File tree

3 files changed

+6
-429
lines changed

3 files changed

+6
-429
lines changed

src/Extensaur.Text/README.md

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Source only package for Text extension methods and text building utilities for .NET
44

5-
This package provides advanced text manipulation utilities including named placeholder formatting, enhanced StringBuilder operations, and high-performance string building with minimal heap allocations. These tools are designed for scenarios requiring efficient string composition, template processing, and conditional text generation.
5+
This package provides advanced text manipulation utilities including named placeholder formatting and enhanced StringBuilder operations. These tools are designed for scenarios requiring efficient string composition, template processing, and conditional text generation.
66

77
## Core Classes
88

@@ -113,73 +113,10 @@ var result = new StringBuilder()
113113
- **Fluent Interface**: All methods return `StringBuilder` for method chaining
114114
- **Type Safety**: Generic support for any collection type
115115

116-
### ValueStringBuilder
117-
118-
A high-performance, stack-friendly string builder that minimizes heap allocations by using stack-allocated or pooled buffers. Ideal for performance-critical scenarios with predictable string sizes.
119-
120-
```csharp
121-
using System.Text;
122-
123-
// Stack-allocated buffer for small strings
124-
Span<char> buffer = stackalloc char[256];
125-
using var builder = new ValueStringBuilder(buffer);
126-
127-
builder.Append("Processing items: ");
128-
for (int i = 0; i < items.Length; i++)
129-
{
130-
if (i > 0) builder.Append(", ");
131-
builder.Append(items[i].ToString());
132-
}
133-
134-
string result = builder.ToString(); // Efficient conversion to string
135-
136-
// Pool-based allocation for larger strings
137-
using var largeBuilder = new ValueStringBuilder(1024);
138-
largeBuilder.Append("Large content...");
139-
140-
// Insert operations
141-
largeBuilder.Insert(0, "Prefix: ");
142-
largeBuilder.Insert(largeBuilder.Length, " :Suffix");
143-
144-
// Span-based operations for maximum efficiency
145-
ReadOnlySpan<char> content = largeBuilder.AsSpan();
146-
bool success = largeBuilder.TryCopyTo(destinationBuffer, out int written);
147-
148-
// Character-level access
149-
for (int i = 0; i < builder.Length; i++)
150-
{
151-
ref char c = ref builder[i]; // Direct reference to buffer
152-
if (c == 'a') c = 'A'; // In-place modification
153-
}
154-
155-
// Advanced buffer management
156-
builder.EnsureCapacity(500); // Pre-allocate capacity
157-
Span<char> appendBuffer = builder.AppendSpan(10); // Get span for direct writing
158-
// Write directly to appendBuffer...
159-
160-
// Null-terminated strings for interop
161-
ref char pinned = ref builder.GetPinnableReference(terminate: true);
162-
```
163-
164-
**Key Features:**
165-
166-
- **Zero Heap Allocation**: Uses stack buffers or pooled arrays to avoid GC pressure
167-
- **High Performance**: Direct buffer manipulation with minimal overhead
168-
- **Flexible Initialization**: Stack-allocated span or pooled array backing
169-
- **Direct Buffer Access**: Reference-based character access for in-place modifications
170-
- **Span Integration**: Full integration with `Span<char>` and `ReadOnlySpan<char>`
171-
- **Memory Pool Integration**: Automatic return of rented arrays via `Dispose()`
172-
- **Capacity Management**: Manual capacity control for optimal performance
173-
174116
## Performance Notes
175117

176118
- **NameFormatter**: Optimized property reflection with minimal overhead for simple properties; nested properties use efficient dot-notation parsing
177119
- **StringBuilderExtensions**: All operations maintain StringBuilder's performance characteristics while adding convenience
178-
- **ValueStringBuilder**: Designed for high-performance scenarios:
179-
- Stack allocation eliminates heap allocations for small strings (< 256 chars typically)
180-
- Pool allocation reduces GC pressure for larger strings
181-
- Direct buffer access enables in-place modifications without string copies
182-
- Span-based operations provide zero-copy string processing
183120

184121
## Compiler Configuration
185122

src/Extensaur/Collections/EnumerableExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ static class EnumerableExtensions
3434
/// </remarks>
3535
public static object ElementAt(this IEnumerable source, int index)
3636
{
37-
ArgumentNullException.ThrowIfNull(source);
38-
ArgumentOutOfRangeException.ThrowIfNegative(index);
37+
if (source is null)
38+
throw new ArgumentNullException(nameof(source));
39+
40+
if (index < 0)
41+
throw new ArgumentOutOfRangeException(nameof(index), "Index cannot be negative.");
3942

4043
var item = source.ElementAtOrDefault(index);
4144

0 commit comments

Comments
 (0)