This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10d32ad
commit c0fe750
Showing
4 changed files
with
129 additions
and
98 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/System.Buffers.Experimental/System/Buffers/BufferReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Sequences; | ||
|
||
namespace System.Buffers | ||
{ | ||
public static partial class BufferReaderExtensions | ||
{ | ||
//public Position? PositionOf(byte value) | ||
//{ | ||
// var unread = UnreadSegment; | ||
// var index = unread.IndexOf(value); | ||
// if (index != -1) return _currentPosition + (_index + index); | ||
|
||
// var nextSegmentPosition = _nextPosition; | ||
// var currentSegmentPosition = _nextPosition; | ||
// while (_sequence.TryGet(ref nextSegmentPosition, out var memory, true)) | ||
// { | ||
// var segment = memory.Span; | ||
// index = segment.IndexOf(value); | ||
// if (index != -1) return currentSegmentPosition + index; | ||
// currentSegmentPosition = nextSegmentPosition; | ||
// } | ||
// return default; | ||
//} | ||
|
||
//public Position? PositionOf(ReadOnlySpan<byte> value) | ||
//{ | ||
// var unread = UnreadSegment; | ||
// var index = unread.IndexOf(value); | ||
// if (index != -1) return _currentPosition + (_index + index); | ||
// if (value.Length == 0) return default; | ||
|
||
// Span<byte> temp = stackalloc byte[(value.Length - 1) * 2]; | ||
// var currentSegmentPosition = _currentPosition; | ||
// var nextSegmentPosition = _nextPosition; | ||
// var currentSegmentConsumedBytes = _index; | ||
|
||
// while (true) | ||
// { | ||
// // Try Stitched Match | ||
// int tempStartIndex = unread.Length - Math.Min(unread.Length, value.Length - 1); | ||
// var candidatePosition = currentSegmentPosition + (currentSegmentConsumedBytes + tempStartIndex); | ||
// int copied = CopyFromPosition(_sequence, candidatePosition, temp); | ||
// if (copied < value.Length) return null; | ||
|
||
// index = temp.Slice(0, copied).IndexOf(value); | ||
// if (index < value.Length) | ||
// { | ||
// if (index != -1) return candidatePosition + index; | ||
// } | ||
|
||
// currentSegmentPosition = nextSegmentPosition; | ||
// // Try Next Segment | ||
// if (!_sequence.TryGet(ref nextSegmentPosition, out var memory, true)) | ||
// { | ||
// return default; | ||
// } | ||
// currentSegmentConsumedBytes = 0; | ||
// unread = memory.Span; | ||
|
||
// index = unread.IndexOf(value); | ||
// if (index != -1) return currentSegmentPosition + index; | ||
// } | ||
//} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters