Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Common/src/System/NotImplemented.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ internal static Exception ByDesignWithMessage(string message)
/// Temporary NotImplementedException with no message shown to user.
/// Example: Exception.ActiveIssue("https://github.com/dotnet/corefx/issues/xxxx") or Exception.ActiveIssue("TFS xxxxxx").
/// </summary>
internal static Exception ActiveIssue(string issue) => new NotImplementedException();
internal static Exception ActiveIssue(string issue) => new NotImplementedException();
}
}
2 changes: 1 addition & 1 deletion src/Common/tests/System/PerfUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public string CreateString(int length)
for (int i = 0; i < str.Length; i++)
{
// Add path separator so folders aren't too long.
if (i%20 == 0)
if (i % 20 == 0)
{
str[i] = Path.DirectorySeparatorChar;
}
Expand Down
38 changes: 22 additions & 16 deletions src/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public readonly ref struct ReadOnlySpan<T>
[CLSCompliant(false)]
public unsafe ReadOnlySpan(void* pointer, int length) { throw null; }
public bool IsEmpty { get { throw null; } }
public T this[int index] { get { throw null; }}
public T this[int index] { get { throw null; } }
public int Length { get { throw null; } }
public void CopyTo(Span<T> destination) { }
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -32,8 +32,8 @@ public void CopyTo(Span<T> destination) { }
public override int GetHashCode() { throw null; }
#pragma warning restore 0809
public static bool operator ==(ReadOnlySpan<T> left, ReadOnlySpan<T> right) { throw null; }
public static implicit operator ReadOnlySpan<T> (T[] array) { throw null; }
public static implicit operator ReadOnlySpan<T> (ArraySegment<T> arraySegment) { throw null; }
public static implicit operator ReadOnlySpan<T>(T[] array) { throw null; }
public static implicit operator ReadOnlySpan<T>(ArraySegment<T> arraySegment) { throw null; }
public static bool operator !=(ReadOnlySpan<T> left, ReadOnlySpan<T> right) { throw null; }
public ReadOnlySpan<T> Slice(int start) { throw null; }
public ReadOnlySpan<T> Slice(int start, int length) { throw null; }
Expand Down Expand Up @@ -73,9 +73,9 @@ public void CopyTo(Span<T> destination) { }
public override int GetHashCode() { throw null; }
#pragma warning restore 0809
public static bool operator ==(Span<T> left, Span<T> right) { throw null; }
public static implicit operator Span<T> (T[] array) { throw null; }
public static implicit operator Span<T> (ArraySegment<T> arraySegment) { throw null; }
public static implicit operator ReadOnlySpan<T> (Span<T> span) { throw null; }
public static implicit operator Span<T>(T[] array) { throw null; }
public static implicit operator Span<T>(ArraySegment<T> arraySegment) { throw null; }
public static implicit operator ReadOnlySpan<T>(Span<T> span) { throw null; }
public static bool operator !=(Span<T> left, Span<T> right) { throw null; }
public Span<T> Slice(int start) { throw null; }
public Span<T> Slice(int start, int length) { throw null; }
Expand All @@ -87,7 +87,7 @@ public ref struct Enumerator
public ref T Current { get { throw null; } }
}
}

public static class MemoryExtensions
{
public static int IndexOf<T>(this Span<T> span, T value) where T : IEquatable<T> { throw null; }
Expand All @@ -97,8 +97,11 @@ public static class MemoryExtensions
public static int IndexOfAny(this Span<byte> span, byte value0, byte value1, byte value2) { throw null; }
public static int IndexOfAny(this Span<byte> span, ReadOnlySpan<byte> values) { throw null; }

public static int LastIndexOf<T>(this Span<T> span, T value) where T : IEquatable<T> { throw null; }
public static int LastIndexOf<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }

public static bool SequenceEqual<T>(this Span<T> first, ReadOnlySpan<T> second) where T : IEquatable<T> { throw null; }

public static bool StartsWith<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }

public static bool EndsWith<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }
Expand All @@ -107,7 +110,7 @@ public static class MemoryExtensions
public static Span<byte> AsBytes<T>(this Span<T> source) where T : struct { throw null; }

public static Span<TTo> NonPortableCast<TFrom, TTo>(this Span<TFrom> source) where TFrom : struct where TTo : struct { throw null; }

public static ReadOnlySpan<char> AsReadOnlySpan(this string text) { throw null; }
public static ReadOnlyMemory<char> AsReadOnlyMemory(this string text) { throw null; }

Expand All @@ -128,12 +131,15 @@ public static class MemoryExtensions
public static int IndexOfAny(this ReadOnlySpan<byte> span, byte value0, byte value1, byte value2) { throw null; }
public static int IndexOfAny(this ReadOnlySpan<byte> span, ReadOnlySpan<byte> values) { throw null; }

public static int LastIndexOf<T>(this ReadOnlySpan<T> span, T value) where T : IEquatable<T> { throw null; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also have LastIndexOfAny for parity?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I will add those in a later PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you file an issue? Thanks.

public static int LastIndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }

public static bool SequenceEqual<T>(this ReadOnlySpan<T> first, ReadOnlySpan<T> second) where T : IEquatable<T> { throw null; }

public static bool StartsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }

public static ReadOnlySpan<byte> AsBytes<T>(this ReadOnlySpan<T> source) where T : struct { throw null; }

public static ReadOnlySpan<TTo> NonPortableCast<TFrom, TTo>(this ReadOnlySpan<TFrom> source) where TFrom : struct where TTo : struct { throw null; }

public static bool TryGetString(this ReadOnlyMemory<char> readOnlyMemory, out string text, out int start, out int length) { throw null; }
Expand Down Expand Up @@ -197,23 +203,23 @@ public void CopyTo(Memory<T> destination) { }

namespace System.Buffers
{
public unsafe struct MemoryHandle : IDisposable
public unsafe struct MemoryHandle : IDisposable
{
[CLSCompliant(false)]
public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default(System.Runtime.InteropServices.GCHandle)) { throw null; }
public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default) { throw null; }
[CLSCompliant(false)]
public void* Pointer { get { throw null; } }
public bool HasPointer { get { throw null; } }
public void Dispose() { throw null; }
}

public interface IRetainable
public interface IRetainable
{
bool Release();
void Retain();
}
public abstract class OwnedMemory<T> : IDisposable, IRetainable

public abstract class OwnedMemory<T> : IDisposable, IRetainable
{
public Memory<T> Memory { get { throw null; } }
public abstract bool IsDisposed { get; }
Expand Down Expand Up @@ -353,7 +359,7 @@ namespace System.Buffers
public bool IsDefault => throw null;
public byte Precision => throw null;
public char Symbol => throw null;
public static implicit operator StandardFormat (char symbol) => throw null;
public static implicit operator StandardFormat(char symbol) => throw null;
public static StandardFormat Parse(ReadOnlySpan<char> format) => throw null;
public static StandardFormat Parse(string format) => throw null;
public override bool Equals(object obj) => throw null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static ulong ReadUInt64LittleEndian(ReadOnlySpan<byte> buffer)
}
return result;
}

/// <summary>
/// Reads an Int16 out of a read-only span of bytes as little endian.
/// <returns>If the span is too small to contain an Int16, return false.</returns>
Expand Down
10 changes: 5 additions & 5 deletions src/System.Memory/src/System/Buffers/MemoryHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ internal void AddOffset(int offset)
/// Frees the pinned handle and releases IRetainable.
/// </summary>
public void Dispose()
{
if (_handle.IsAllocated)
{
if (_handle.IsAllocated)
{
_handle.Free();
}

if (_retainable != null)
if (_retainable != null)
{
_retainable.Release();
_retainable = null;
}

_pointer = null;
_pointer = null;
}

}
}
6 changes: 3 additions & 3 deletions src/System.Memory/src/System/Buffers/OwnedMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public abstract class OwnedMemory<T> : IDisposable, IRetainable
/// </exception>
public Memory<T> Memory
{
get
get
{
if (IsDisposed)
if (IsDisposed)
{
ThrowHelper.ThrowObjectDisposedException_MemoryDisposed(nameof(OwnedMemory<T>));
}
Expand All @@ -60,7 +60,7 @@ public Memory<T> Memory
/// </exception>
public void Dispose()
{
if (IsRetained)
if (IsRetained)
{
ThrowHelper.ThrowInvalidOperationException_OutstandingReferences();
}
Expand Down
68 changes: 43 additions & 25 deletions src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> utf8, Span<byte>
int sourceIndex = 0;
int destIndex = 0;

if (utf8.Length == 0) goto DoneExit;
if (utf8.Length == 0)
goto DoneExit;

ref sbyte decodingMap = ref s_decodingMap[0];

Expand All @@ -59,24 +60,27 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> utf8, Span<byte>
while (sourceIndex < maxSrcLength)
{
int result = Decode(ref Unsafe.Add(ref srcBytes, sourceIndex), ref decodingMap);
if (result < 0) goto InvalidExit;
if (result < 0)
goto InvalidExit;
WriteThreeLowOrderBytes(ref Unsafe.Add(ref destBytes, destIndex), result);
destIndex += 3;
sourceIndex += 4;
}

if (maxSrcLength != srcLength - skipLastChunk) goto DestinationSmallExit;
if (maxSrcLength != srcLength - skipLastChunk)
goto DestinationSmallExit;

// If input is less than 4 bytes, srcLength == sourceIndex == 0
// If input is not a multiple of 4, sourceIndex == srcLength != 0
if (sourceIndex == srcLength)
{
if (isFinalBlock) goto InvalidExit;
if (isFinalBlock)
goto InvalidExit;
goto NeedMoreExit;
}

// if isFinalBlock is false, we will never reach this point

int i0 = Unsafe.Add(ref srcBytes, srcLength - 4);
int i1 = Unsafe.Add(ref srcBytes, srcLength - 3);
int i2 = Unsafe.Add(ref srcBytes, srcLength - 2);
Expand All @@ -100,8 +104,10 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> utf8, Span<byte>
i0 |= i3;
i0 |= i2;

if (i0 < 0) goto InvalidExit;
if (destIndex > destLength - 3) goto DestinationSmallExit;
if (i0 < 0)
goto InvalidExit;
if (destIndex > destLength - 3)
goto DestinationSmallExit;
WriteThreeLowOrderBytes(ref Unsafe.Add(ref destBytes, destIndex), i0);
destIndex += 3;
}
Expand All @@ -113,41 +119,47 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> utf8, Span<byte>

i0 |= i2;

if (i0 < 0) goto InvalidExit;
if (destIndex > destLength - 2) goto DestinationSmallExit;
if (i0 < 0)
goto InvalidExit;
if (destIndex > destLength - 2)
goto DestinationSmallExit;
Unsafe.Add(ref destBytes, destIndex) = (byte)(i0 >> 16);
Unsafe.Add(ref destBytes, destIndex + 1) = (byte)(i0 >> 8);
destIndex += 2;
}
else
{
if (i0 < 0) goto InvalidExit;
if (destIndex > destLength - 1) goto DestinationSmallExit;
if (i0 < 0)
goto InvalidExit;
if (destIndex > destLength - 1)
goto DestinationSmallExit;
Unsafe.Add(ref destBytes, destIndex) = (byte)(i0 >> 16);
destIndex += 1;
}

sourceIndex += 4;

if (srcLength != utf8.Length) goto InvalidExit;
if (srcLength != utf8.Length)
goto InvalidExit;

DoneExit:
DoneExit:
consumed = sourceIndex;
written = destIndex;
return OperationStatus.Done;

DestinationSmallExit:
if (srcLength != utf8.Length && isFinalBlock) goto InvalidExit; // if input is not a multiple of 4, and there is no more data, return invalid data instead
DestinationSmallExit:
if (srcLength != utf8.Length && isFinalBlock)
goto InvalidExit; // if input is not a multiple of 4, and there is no more data, return invalid data instead
consumed = sourceIndex;
written = destIndex;
return OperationStatus.DestinationTooSmall;

NeedMoreExit:
NeedMoreExit:
consumed = sourceIndex;
written = destIndex;
return OperationStatus.NeedMoreData;

InvalidExit:
InvalidExit:
consumed = sourceIndex;
written = destIndex;
return OperationStatus.InvalidData;
Expand Down Expand Up @@ -190,8 +202,10 @@ public static OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, out int w
int destIndex = 0;

// only decode input if it is a multiple of 4
if (bufferLength != ((bufferLength >> 2) * 4)) goto InvalidExit;
if (bufferLength == 0) goto DoneExit;
if (bufferLength != ((bufferLength >> 2) * 4))
goto InvalidExit;
if (bufferLength == 0)
goto DoneExit;

ref byte bufferBytes = ref buffer.DangerousGetPinnableReference();

Expand All @@ -200,7 +214,8 @@ public static OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, out int w
while (sourceIndex < bufferLength - 4)
{
int result = Decode(ref Unsafe.Add(ref bufferBytes, sourceIndex), ref decodingMap);
if (result < 0) goto InvalidExit;
if (result < 0)
goto InvalidExit;
WriteThreeLowOrderBytes(ref Unsafe.Add(ref bufferBytes, destIndex), result);
destIndex += 3;
sourceIndex += 4;
Expand Down Expand Up @@ -229,7 +244,8 @@ public static OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, out int w
i0 |= i3;
i0 |= i2;

if (i0 < 0) goto InvalidExit;
if (i0 < 0)
goto InvalidExit;
WriteThreeLowOrderBytes(ref Unsafe.Add(ref bufferBytes, destIndex), i0);
destIndex += 3;
}
Expand All @@ -241,23 +257,25 @@ public static OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, out int w

i0 |= i2;

if (i0 < 0) goto InvalidExit;
if (i0 < 0)
goto InvalidExit;
Unsafe.Add(ref bufferBytes, destIndex) = (byte)(i0 >> 16);
Unsafe.Add(ref bufferBytes, destIndex + 1) = (byte)(i0 >> 8);
destIndex += 2;
}
else
{
if (i0 < 0) goto InvalidExit;
if (i0 < 0)
goto InvalidExit;
Unsafe.Add(ref bufferBytes, destIndex) = (byte)(i0 >> 16);
destIndex += 1;
}

DoneExit:
DoneExit:
written = destIndex;
return OperationStatus.Done;

InvalidExit:
InvalidExit:
written = destIndex;
return OperationStatus.InvalidData;
}
Expand Down
Loading