Skip to content

Commit 6f97a43

Browse files
committed
Renamed PooledSpan to TempSpan
1 parent dc54965 commit 6f97a43

12 files changed

+41
-41
lines changed

src/LibObjectFile/Collections/PooledSpan.cs renamed to src/LibObjectFile/Collections/TempSpan.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,63 @@ namespace LibObjectFile.Collections;
1212
/// Represents a pooled span that can be created from a stack or heap memory.
1313
/// </summary>
1414
/// <typeparam name="T">The type of the elements in the span.</typeparam>
15-
public readonly ref struct PooledSpan<T> where T : unmanaged
15+
public readonly ref struct TempSpan<T> where T : unmanaged
1616
{
1717
private readonly Span<T> _span;
1818
private readonly byte[]? _buffer;
1919

2020
/// <summary>
21-
/// Initializes a new instance of the <see cref="PooledSpan{T}"/> struct using a stack memory span.
21+
/// Initializes a new instance of the <see cref="TempSpan{T}"/> struct using a stack memory span.
2222
/// </summary>
2323
/// <param name="span">The stack memory span.</param>
2424
/// <param name="size">The size of the span in bytes.</param>
25-
private PooledSpan(Span<byte> span, int size)
25+
private TempSpan(Span<byte> span, int size)
2626
{
2727
_span = MemoryMarshal.Cast<byte, T>(span.Slice(0, size));
2828
_buffer = null;
2929
}
3030

3131
/// <summary>
32-
/// Initializes a new instance of the <see cref="PooledSpan{T}"/> struct using a heap memory span.
32+
/// Initializes a new instance of the <see cref="TempSpan{T}"/> struct using a heap memory span.
3333
/// </summary>
3434
/// <param name="buffer">The heap memory buffer.</param>
3535
/// <param name="size">The size of the span in bytes.</param>
36-
private PooledSpan(byte[] buffer, int size)
36+
private TempSpan(byte[] buffer, int size)
3737
{
3838
_span = MemoryMarshal.Cast<byte, T>(new(buffer, 0, size));
3939
_buffer = buffer;
4040
}
4141

4242
/// <summary>
43-
/// Creates a new instance of the <see cref="PooledSpan{T}"/> struct with the specified number of elements.
43+
/// Creates a new instance of the <see cref="TempSpan{T}"/> struct with the specified number of elements.
4444
/// </summary>
4545
/// <param name="count">The number of elements in the span.</param>
46-
/// <returns>A new instance of the <see cref="PooledSpan{T}"/> struct.</returns>
47-
public static unsafe PooledSpan<T> Create(int count, out Span<T> span)
46+
/// <returns>A new instance of the <see cref="TempSpan{T}"/> struct.</returns>
47+
public static unsafe TempSpan<T> Create(int count, out Span<T> span)
4848
{
4949
ArgumentOutOfRangeException.ThrowIfLessThan(count, 0);
5050
var size = count * sizeof(T);
5151
var buffer = ArrayPool<byte>.Shared.Rent(size);
52-
var pooledSpan = new PooledSpan<T>(buffer, size);
53-
span = pooledSpan.Span;
54-
return pooledSpan;
52+
var tempSpan = new TempSpan<T>(buffer, size);
53+
span = tempSpan.Span;
54+
return tempSpan;
5555
}
5656

5757
/// <summary>
58-
/// Creates a new instance of the <see cref="PooledSpan{T}"/> struct with the specified number of elements, using a stack memory span if possible.
58+
/// Creates a new instance of the <see cref="TempSpan{T}"/> struct with the specified number of elements, using a stack memory span if possible.
5959
/// </summary>
6060
/// <param name="stackSpan">The stack memory span.</param>
6161
/// <param name="count">The number of elements in the span.</param>
62-
/// <returns>A new instance of the <see cref="PooledSpan{T}"/> struct.</returns>
63-
public static unsafe PooledSpan<T> Create(Span<byte> stackSpan, int count, out Span<T> span)
62+
/// <returns>A new instance of the <see cref="TempSpan{T}"/> struct.</returns>
63+
public static unsafe TempSpan<T> Create(Span<byte> stackSpan, int count, out Span<T> span)
6464
{
6565
ArgumentOutOfRangeException.ThrowIfLessThan(count, 0);
6666
var size = count * sizeof(T);
6767
if (size <= stackSpan.Length)
6868
{
69-
var pooledSpan = new PooledSpan<T>(stackSpan, size);
70-
span = pooledSpan.Span;
71-
return pooledSpan;
69+
var tempSpan = new TempSpan<T>(stackSpan, size);
70+
span = tempSpan.Span;
71+
return tempSpan;
7272
}
7373

7474
return Create(count, out span);
@@ -99,12 +99,12 @@ public void Dispose()
9999
/// <summary>
100100
/// Gets the span of elements.
101101
/// </summary>
102-
/// <param name="pooledSpan">The pooled span to convert.</param>
103-
public static implicit operator Span<T>(PooledSpan<T> pooledSpan) => pooledSpan.Span;
102+
/// <param name="tempSpan">The pooled span to convert.</param>
103+
public static implicit operator Span<T>(TempSpan<T> tempSpan) => tempSpan.Span;
104104

105105
/// <summary>
106106
/// Gets the span of elements as a span of bytes.
107107
/// </summary>
108-
/// <param name="pooledSpan">The pooled span to convert.</param>
109-
public static implicit operator Span<byte>(PooledSpan<T> pooledSpan) => pooledSpan.AsBytes;
108+
/// <param name="tempSpan">The pooled span to convert.</param>
109+
public static implicit operator Span<byte>(TempSpan<T> tempSpan) => tempSpan.AsBytes;
110110
}

src/LibObjectFile/PE/DataDirectory/PEBoundImportDirectory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public override unsafe void Read(PEImageReader reader)
7979

8080
if (rawEntry.NumberOfModuleForwarderRefs > 0)
8181
{
82-
using var pooledSpan = PooledSpan<RawPEBoundImportForwarderRef>.Create(rawEntry.NumberOfModuleForwarderRefs, out var spanForwarderRef);
83-
var span = pooledSpan.AsBytes;
82+
using var tempSpan = TempSpan<RawPEBoundImportForwarderRef>.Create(rawEntry.NumberOfModuleForwarderRefs, out var spanForwarderRef);
83+
var span = tempSpan.AsBytes;
8484

8585
read = reader.Read(span);
8686
if (read != span.Length)

src/LibObjectFile/PE/DataDirectory/PEDebugDirectory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public override unsafe void Read(PEImageReader reader)
3030

3131
// Scope the pooled span to ensure it is returned to the pool as soon as possible
3232
{
33-
using var pooledSpan = PooledSpan<RawImageDebugDirectory>.Create(entryCount, out var entries);
34-
Span<byte> span = pooledSpan;
33+
using var tempSpan = TempSpan<RawImageDebugDirectory>.Create(entryCount, out var entries);
34+
Span<byte> span = tempSpan;
3535

3636
reader.Position = Position;
3737
int read = reader.Read(span);
@@ -132,7 +132,7 @@ internal override IEnumerable<PEObjectBase> CollectImplicitSectionDataList()
132132
public override void Write(PEImageWriter writer)
133133
{
134134
var entries = CollectionsMarshal.AsSpan(Entries);
135-
using var pooledSpan = PooledSpan<RawImageDebugDirectory>.Create(entries.Length, out var rawEntries);
135+
using var tempSpan = TempSpan<RawImageDebugDirectory>.Create(entries.Length, out var rawEntries);
136136

137137
RawImageDebugDirectory rawEntry = default;
138138
for (var i = 0; i < entries.Length; i++)
@@ -160,7 +160,7 @@ public override void Write(PEImageWriter writer)
160160
rawEntries[i] = rawEntry;
161161
}
162162

163-
writer.Write(pooledSpan);
163+
writer.Write(tempSpan);
164164
}
165165

166166
protected override unsafe uint ComputeHeaderSize(PELayoutContext context)

src/LibObjectFile/PE/DataDirectory/PEDebugSectionDataRSDS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public PEDebugSectionDataRSDS()
4646
public override unsafe void Read(PEImageReader reader)
4747
{
4848
var size = (int)Size;
49-
using var pooledSpan = PooledSpan<byte>.Create(size, out var span);
49+
using var tempSpan = TempSpan<byte>.Create(size, out var span);
5050

5151
reader.Position = Position;
5252
var read = reader.Read(span);

src/LibObjectFile/PE/DataDirectory/PEDelayImportDirectory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private unsafe uint CalculateSize()
217217
public override unsafe void Write(PEImageWriter writer)
218218
{
219219
var entries = CollectionsMarshal.AsSpan(Entries);
220-
using var pooledSpan = PooledSpan<RawDelayLoadDescriptor>.Create(entries.Length + 1, out var rawEntries);
220+
using var tempSpan = TempSpan<RawDelayLoadDescriptor>.Create(entries.Length + 1, out var rawEntries);
221221

222222
RawDelayLoadDescriptor rawEntry = default;
223223
for (var i = 0; i < entries.Length; i++)
@@ -238,6 +238,6 @@ public override unsafe void Write(PEImageWriter writer)
238238
// Write the null entry
239239
rawEntries[entries.Length] = default;
240240

241-
writer.Write(pooledSpan.AsBytes);
241+
writer.Write(tempSpan.AsBytes);
242242
}
243243
}

src/LibObjectFile/PE/DataDirectory/PEExceptionDirectory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override unsafe void Read(PEImageReader reader)
118118

119119
reader.Position = Position;
120120
{
121-
using var pooledSpan = PooledSpan<byte>.Create((int)size, out var span);
121+
using var tempSpan = TempSpan<byte>.Create((int)size, out var span);
122122
int read = reader.Read(span);
123123
if (read != size)
124124
{

src/LibObjectFile/PE/DataDirectory/PEExportAddressTable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public override unsafe void UpdateLayout(PELayoutContext context)
3838

3939
public override unsafe void Read(PEImageReader reader)
4040
{
41-
using var pooledSpan = PooledSpan<RVA>.Create(Values.Count, out var spanRva);
42-
var span = pooledSpan.AsBytes;
41+
using var tempSpan = TempSpan<RVA>.Create(Values.Count, out var spanRva);
42+
var span = tempSpan.AsBytes;
4343

4444
reader.Position = Position;
4545
int read = reader.Read(span);

src/LibObjectFile/PE/DataDirectory/PEExportNameTable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public override unsafe void UpdateLayout(PELayoutContext context)
3434
public override unsafe void Read(PEImageReader reader)
3535
{
3636
reader.Position = Position;
37-
using var pooledSpan = PooledSpan<RVA>.Create(Values.Count, out var spanRva);
38-
var span = pooledSpan.AsBytes;
37+
using var tempSpan = TempSpan<RVA>.Create(Values.Count, out var spanRva);
38+
var span = tempSpan.AsBytes;
3939

4040
int read = reader.Read(span);
4141
if (read != span.Length)

src/LibObjectFile/PE/DataDirectory/PEImportFunctionTable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void Write(PEImageWriter writer)
134134

135135
private unsafe void Write32(PEImageWriter writer)
136136
{
137-
using var pooledSpan = PooledSpan<RawImportFunctionEntry32>.Create(Entries.Count, out var span);
137+
using var tempSpan = TempSpan<RawImportFunctionEntry32>.Create(Entries.Count, out var span);
138138

139139
for (var i = 0; i < Entries.Count; i++)
140140
{
@@ -146,7 +146,7 @@ private unsafe void Write32(PEImageWriter writer)
146146
// Last entry is null terminator
147147
span[^1] = default;
148148

149-
writer.Write(pooledSpan);
149+
writer.Write(tempSpan);
150150
}
151151

152152
private unsafe void Write64(PEImageWriter writer)

src/LibObjectFile/PE/DataDirectory/PEResourceDirectoryEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void ReadEntry(PEImageReader reader, PEResourceDirectory directory, RawI
127127
{
128128
// Read the string
129129
var length = reader.ReadU16() * 2;
130-
using var pooledSpan = PooledSpan<byte>.Create(length, out var span);
130+
using var tempSpan = TempSpan<byte>.Create(length, out var span);
131131

132132
int readLength = reader.Read(span);
133133
if (readLength != length)

0 commit comments

Comments
 (0)