Skip to content

Commit 7ece0bf

Browse files
committed
expose pointer field publicly to avoid the property
1 parent dab9d57 commit 7ece0bf

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

core/MemoryAddress.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ public unsafe struct MemoryAddress : IDisposable, IEquatable<MemoryAddress>
1818
/// </summary>
1919
public static readonly int size = IntPtr.Size;
2020

21-
private byte* pointer;
22-
2321
/// <summary>
24-
/// Native address of this memory.
22+
/// Native pointer to the memory.
2523
/// </summary>
26-
public readonly nint Address => (nint)pointer;
24+
public byte* pointer;
2725

2826
/// <summary>
29-
/// Native pointer of this memory.
27+
/// Native address of this memory.
3028
/// </summary>
31-
public readonly byte* Pointer => pointer;
29+
public readonly nint Address => (nint)pointer;
3230

3331
/// <summary>
3432
/// Gets or sets a byte at the given index.
@@ -40,7 +38,7 @@ public readonly ref byte this[int index]
4038
ThrowIfDefault(pointer);
4139
MemoryTracker.ThrowIfOutOfBounds(pointer, index);
4240

43-
return ref pointer[index];
41+
return ref pointer[(uint)index];
4442
}
4543
}
4644

core/Objects/ByteReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public ByteReader(Stream stream, int bytePosition = 0)
8282
{
8383
int byteLength = (int)stream.Length;
8484
MemoryAddress streamData = MemoryAddress.Allocate(byteLength);
85-
Span<byte> span = new(streamData.Pointer, byteLength);
85+
Span<byte> span = new(streamData.pointer, byteLength);
8686
byteLength = stream.Read(span);
8787
reader = MemoryAddress.AllocatePointer<ByteReaderPointer>();
8888
reader->isOriginal = true;
@@ -155,7 +155,7 @@ public readonly Span<byte> GetBytes()
155155
{
156156
MemoryAddress.ThrowIfDefault(reader);
157157

158-
return new(reader->data.Pointer, reader->byteLength);
158+
return new(reader->data.pointer, reader->byteLength);
159159
}
160160

161161
/// <summary>
@@ -182,7 +182,7 @@ public readonly Span<byte> GetRemainingBytes()
182182
{
183183
MemoryAddress.ThrowIfDefault(reader);
184184

185-
return new(reader->data.Pointer + reader->bytePosition, reader->byteLength - reader->bytePosition);
185+
return new(reader->data.pointer + reader->bytePosition, reader->byteLength - reader->bytePosition);
186186
}
187187

188188
[Conditional("DEBUG")]
@@ -315,7 +315,7 @@ public readonly Span<T> PeekSpan<T>(int bytePosition, int length) where T : unma
315315
int byteLength = sizeof(T) * length;
316316
ThrowIfReadingPastLength(bytePosition + byteLength);
317317

318-
void* pointer = reader->data.Pointer + bytePosition;
318+
void* pointer = reader->data.pointer + bytePosition;
319319
return new(pointer, length);
320320
}
321321

core/Objects/ByteWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public readonly Span<byte> AsSpan()
433433
{
434434
MemoryAddress.ThrowIfDefault(writer);
435435

436-
return new(writer->data.Pointer, writer->bytePosition);
436+
return new(writer->data.pointer, writer->bytePosition);
437437
}
438438

439439
/// <inheritdoc/>

core/Objects/Text.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public Text(int length, char defaultCharacter = ' ')
108108
text = MemoryAddress.AllocatePointer<TextPointer>();
109109
text->length = length;
110110
text->buffer = MemoryAddress.Allocate(length * sizeof(char));
111-
new Span<char>(text->buffer.Pointer, length).Fill(defaultCharacter);
111+
new Span<char>(text->buffer.pointer, length).Fill(defaultCharacter);
112112
}
113113

114114
/// <summary>
@@ -192,7 +192,7 @@ public readonly Span<char> AsSpan()
192192
{
193193
MemoryAddress.ThrowIfDefault(text);
194194

195-
return new Span<char>(text->buffer.Pointer, text->length);
195+
return new Span<char>(text->buffer.pointer, text->length);
196196
}
197197

198198
/// <summary>
@@ -212,7 +212,7 @@ public readonly void CopyTo(Span<char> destination)
212212
{
213213
MemoryAddress.ThrowIfDefault(text);
214214

215-
new Span<char>(text->buffer.Pointer, text->length).CopyTo(destination);
215+
new Span<char>(text->buffer.pointer, text->length).CopyTo(destination);
216216
}
217217

218218
/// <summary>
@@ -228,7 +228,7 @@ public readonly void CopyFrom(ReadOnlySpan<char> source)
228228
MemoryAddress.Resize(ref text->buffer, source.Length * sizeof(char));
229229
}
230230

231-
source.CopyTo(new Span<char>(text->buffer.Pointer, source.Length));
231+
source.CopyTo(new Span<char>(text->buffer.pointer, source.Length));
232232
}
233233

234234
/// <summary>
@@ -244,7 +244,7 @@ public readonly void CopyFrom(string source)
244244
MemoryAddress.Resize(ref text->buffer, source.Length * sizeof(char));
245245
}
246246

247-
source.AsSpan().CopyTo(new Span<char>(text->buffer.Pointer, source.Length));
247+
source.AsSpan().CopyTo(new Span<char>(text->buffer.pointer, source.Length));
248248
}
249249

250250
/// <summary>
@@ -260,7 +260,7 @@ public readonly void CopyFrom(ASCIIText256 source)
260260
MemoryAddress.Resize(ref text->buffer, source.Length * sizeof(char));
261261
}
262262

263-
source.CopyTo(new Span<char>(text->buffer.Pointer, source.Length));
263+
source.CopyTo(new Span<char>(text->buffer.pointer, source.Length));
264264
}
265265

266266
/// <summary>
@@ -340,7 +340,7 @@ public readonly Span<char> Slice(int start)
340340
{
341341
MemoryAddress.ThrowIfDefault(text);
342342

343-
return new Span<char>(text->buffer.Pointer + start * sizeof(char), text->length - start);
343+
return new Span<char>(text->buffer.pointer + start * sizeof(char), text->length - start);
344344
}
345345

346346
/// <summary>
@@ -350,7 +350,7 @@ public readonly Span<char> Slice(int start, int length)
350350
{
351351
MemoryAddress.ThrowIfDefault(text);
352352

353-
return new Span<char>(text->buffer.Pointer + start * sizeof(char), length);
353+
return new Span<char>(text->buffer.pointer + start * sizeof(char), length);
354354
}
355355

356356
/// <summary>
@@ -898,7 +898,7 @@ public readonly long GetLongHashCode()
898898
unchecked
899899
{
900900
long hash = 3074457345618258791;
901-
Span<char> text = new(this.text->buffer.Pointer, this.text->length);
901+
Span<char> text = new(this.text->buffer.pointer, this.text->length);
902902
for (int i = 0; i < text.Length; i++)
903903
{
904904
hash += text[i];

0 commit comments

Comments
 (0)