Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Partial cleanup of SpanExtensionsLab #1348

Merged
merged 5 commits into from
Mar 22, 2017

Conversation

ahsonkhan
Copy link
Contributor

@ahsonkhan ahsonkhan commented Mar 21, 2017

Working towards - #1314 / #1292

  • Move to System.Binary

    • public static T Read(this ReadOnlySpan slice) where T : struct;
    • public static T Read(this Span slice) where T : struct;
    • public static bool TryRead(this ReadOnlySpan slice, out T value) where T : struct;
    • public static bool TryRead(this Span slice, out T value) where T : struct;
    • public static bool TryWrite(this Span slice, T value) where T : struct;
    • public static void Write(this Span slice, T value) where T : struct;
  • Moved to SpanExtensions: (PR Adding Span.StartsWith corefx#17322)

    • public static bool StartsWith(this ReadOnlySpan bytes, ReadOnlySpan slice);
    • public static bool StartsWith(this ReadOnlySpan items, ReadOnlySpan slice) where T : struct, IEquatable;
  • Move to BuffersExtension in experimental

    • public static int IndexOf(this ReadOnlySpan buffer, byte value0, byte value1);
    • public static int IndexOf(this ReadOnlySpan buffer, byte value0, byte value1, byte value2);
    • public static int IndexOf(this Span buffer, byte value0, byte value1);
    • public static int IndexOf(this Span buffer, byte value0, byte value1, byte value2);
    • public static int SequentialIndexOf(this ReadOnlySpan span, byte value);
    • public static int SequentialIndexOf(this Span span, byte value);
    • public static bool TryIndicesOf(this ReadOnlySpan buffer, byte value, Span indices, out int numberOfIndices);
    • public static bool TryIndicesOf(this Span buffer, byte value, Span indices, out int numberOfIndices);
  • Remove (this should be on ArraySegment)

    • public static ArraySegment Slice(this ArraySegment source, int count);
  • Delete:

    • public static bool StartsWith(this ReadOnlySpan str, ReadOnlySpan value);

NOTE:
Moving the following to System.Buffers.Experimental\System\Buffers\BufferExtensions.cs causes System.IO.Pipelines to take a dependency on System.Buffers.Experimental.

    - public static int IndexOf(this ReadOnlySpan<byte> buffer, byte value0, byte value1);
    - public static int IndexOf(this ReadOnlySpan<byte> buffer, byte value0, byte value1, byte value2);
    - public static int IndexOf(this Span<byte> buffer, byte value0, byte value1);
    - public static int IndexOf(this Span<byte> buffer, byte value0, byte value1, byte value2);

The IndexOf with multiple byte values are used in ReadCursorOperations.Seek, here:
https://github.com/aspnet/KestrelHttpServer/blob/f6e5e74d9551df57effda19c856352608374cee7/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs#L273

This function is implemented here:

public static int Seek(ReadCursor begin, ReadCursor end, out ReadCursor result, byte byte0, byte byte1)

What should we do about this dependency? This is the only that System.IO.Pipelines depends on Buffers.Experimental.
If we remove those Seek overloads (and the one reference to it in kestrel), we could remove this dependency.

Edit:
Adding back IndexOf overloads to SpanExtensionsLab (in Buffes.Primitives). Will remove them once they are ported over to corefx (in System.Memory.dll).

@davidfowl
Copy link
Member

Moving the following to System.Buffers.Experimental\System\Buffers\BufferExtensions.cs causes System.IO.Pipelines to take a dependency on System.Buffers.Experimental.

I'm not a fan of this. Move those methods to corefx proper before breaking this package.

@KrzysztofCwalina
Copy link
Member

KrzysztofCwalina commented Mar 21, 2017

Yeah, if the APIs are used by pipelines, and we know they have benefits, we should just have them in SpanExtensions. BTW, I think it would be ok to move the APIs to SpanExtensions without proving they have benefits (perf) and measure later.

Otherwise the PR looks good.

@KrzysztofCwalina
Copy link
Member

Looks good. Thanks!

@KrzysztofCwalina
Copy link
Member

KrzysztofCwalina commented Mar 22, 2017

Ah, I think I merged Ben's rename and now there is a conflict. @ahsonkhan, could you please resolve and then just merge? Thanks.

@ahsonkhan
Copy link
Contributor Author

@KrzysztofCwalina, resolved the conflicts.

@KrzysztofCwalina KrzysztofCwalina merged commit 6017a1b into dotnet:master Mar 22, 2017
@ahsonkhan ahsonkhan deleted the SpanExtensionsWork branch March 22, 2017 22:12
halter73 added a commit to aspnet/KestrelHttpServer that referenced this pull request Mar 23, 2017
halter73 pushed a commit to aspnet/KestrelHttpServer that referenced this pull request Mar 23, 2017
- Removed use of TryRead and follow the pin and use pattern in the other APIs

dotnet/corefxlab#1348
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants