Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Rewritten to use raw-pointers instead of GC-tracked refs
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoidl committed Jan 15, 2019
1 parent 5ace580 commit 0d2cbc4
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 475 deletions.
40 changes: 16 additions & 24 deletions src/System.Memory/src/System/Buffers/Text/Base64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,30 @@ static Base64()
}

[Conditional("DEBUG")]
private static unsafe void AssertRead<TVector>(ref byte src, ref byte srcStart, int srcLength)
private static unsafe void AssertRead<TVector>(byte* src, byte* srcStart, int srcLength)
{
fixed (byte* pSrc = &src)
fixed (byte* pSrcStart = &srcStart)
int vectorElements = Unsafe.SizeOf<TVector>();
byte* readEnd = src + vectorElements;
byte* srcEnd = srcStart + srcLength;

if (readEnd > srcEnd)
{
int vectorElements = Unsafe.SizeOf<TVector>();
byte* readEnd = pSrc + vectorElements;
byte* srcEnd = pSrcStart + srcLength;

if (readEnd > srcEnd)
{
int srcIndex = (int)(pSrc - pSrcStart);
throw new InvalidOperationException($"Read for {typeof(TVector)} is not within safe bounds. srcIndex: {srcIndex}, srcLength: {srcLength}");
}
int srcIndex = (int)(src - srcStart);
throw new InvalidOperationException($"Read for {typeof(TVector)} is not within safe bounds. srcIndex: {srcIndex}, srcLength: {srcLength}");
}
}

[Conditional("DEBUG")]
private static unsafe void AssertWrite<TVector>(ref byte dest, ref byte destStart, int destLength)
private static unsafe void AssertWrite<TVector>(byte* dest, byte* destStart, int destLength)
{
fixed (byte* pDest = &dest)
fixed (byte* pDestStart = &destStart)
int vectorElements = Unsafe.SizeOf<TVector>();
byte* writeEnd = dest + vectorElements;
byte* destEnd = destStart + destLength;

if (writeEnd > destEnd)
{
int vectorElements = Unsafe.SizeOf<TVector>();
byte* writeEnd = pDest + vectorElements;
byte* destEnd = pDestStart + destLength;

if (writeEnd > destEnd)
{
int destIndex = (int)(pDest - pDestStart);
throw new InvalidOperationException($"Write for {typeof(TVector)} is not within safe bounds. destIndex: {destIndex}, destLength: {destLength}");
}
int destIndex = (int)(dest - destStart);
throw new InvalidOperationException($"Write for {typeof(TVector)} is not within safe bounds. destIndex: {destIndex}, destLength: {destLength}");
}
}
}
Expand Down
Loading

0 comments on commit 0d2cbc4

Please sign in to comment.