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

Add GetPosition overload to ReadOnlySequence #27633

Merged
merged 3 commits into from
Mar 2, 2018

Conversation

ahsonkhan
Copy link
Member

SequencePosition c1 = buffer.GetPosition(buffer.Start, 0);
Assert.Equal(0, c1.GetInteger());
Assert.Equal(bufferSegment1, c1.GetObject());
{
Copy link

Choose a reason for hiding this comment

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

Split into two tests

SequencePosition c1 = buffer.GetPosition(buffer.Start, 0);
Assert.Equal(0, c1.GetInteger());
Assert.Equal(bufferSegment1, c1.GetObject());
{
Copy link

Choose a reason for hiding this comment

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

Same here

@@ -24,11 +24,17 @@ public void SegmentStartIsConsideredInBoundsCheck()

var buffer = new ReadOnlySequence<byte>(bufferSegment1, 0, bufferSegment2, 50);

SequencePosition c1 = buffer.GetPosition(buffer.Start, 25); // segment 1 index 75
SequencePosition c2 = buffer.GetPosition(buffer.Start, 55); // segment 2 index 5
SequencePosition c1 = buffer.GetPosition(25); // segment 1 index 75
Copy link
Member

@KrzysztofCwalina KrzysztofCwalina Mar 2, 2018

Choose a reason for hiding this comment

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

I wonder if we should not call the API "PositionAt" (or GetPositionAt). It would allow us to add PositionOf(byte value) in the future without having problems with inconsistent names or overloads.

@davidfowl, @terrajobst

Copy link

Choose a reason for hiding this comment

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

We already have PositionOf(byte value) extension method.

Copy link
Member

Choose a reason for hiding this comment

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

That is my point. We will endup with GetPosition and PositionOf, which is inconsistent. It would be better to have either PositionAt and PositionOf or GetPositionAt and GetPositionOf.

@ahsonkhan
Copy link
Member Author

@dotnet-bot test Windows x64 Debug Build
@dotnet-bot test Windows x86 Release Build

@ahsonkhan
Copy link
Member Author

@dotnet-bot test Linux x64 Release Build
@dotnet-bot test Windows x64 Debug Build
@dotnet-bot test Windows x86 Release Build

@ahsonkhan
Copy link
Member Author

@dotnet-bot test Windows x64 Debug Build
@dotnet-bot test Windows x86 Release Build

@@ -34,7 +34,7 @@ public void AdvanceThrowsIfFlushActiveAndNotConsumedPastThreshold()
Assert.False(flushAsync.IsCompleted);

ReadResult result = _pipe.Reader.ReadAsync().GetAwaiter().GetResult();
SequencePosition consumed = result.Buffer.GetPosition(result.Buffer.Start, 31);
SequencePosition consumed = result.Buffer.GetPosition(31, result.Buffer.Start);
Copy link
Member

Choose a reason for hiding this comment

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

Change this to just specify the length without the position for the ones that pass start.

@@ -19,7 +19,7 @@ public static class BuffersExtensions
int index = sequence.First.Span.IndexOf(value);
if (index != -1)
{
return sequence.GetPosition(sequence.Start, index);
return sequence.GetPosition(index, sequence.Start);
Copy link
Member

Choose a reason for hiding this comment

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

Remove sequence.Start

@ahsonkhan
Copy link
Member Author

@dotnet-bot test OSX x64 Debug Build

@ahsonkhan
Copy link
Member Author

ahsonkhan commented Mar 2, 2018

I am going to ignore the OSX and UWP legs (recently enabled - #27531) that are failing:

Using context: OSX x64 Debug Build
java.nio.channels.ClosedChannelException
Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 131.107.19.186/131.107.19.186:58182
		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1693)
		at hudson.remoting.Request.call(Request.java:192)
		at hudson.remoting.Channel.call(Channel.java:907)
		at hudson.EnvVars.getRemote(EnvVars.java:408)
		at hudson.model.Computer.getEnvironment(Computer.java:1178)
		at org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution$PlaceholderTask$PlaceholderExecutable.run(ExecutorStepExecution.java:628)
		at hudson.model.ResourceController.execute(ResourceController.java:97)
		at hudson.model.Executor.run(Executor.java:429)
Caused: hudson.remoting.RequestAbortedException
	at hudson.remoting.Request.abort(Request.java:329)
	at hudson.remoting.Channel.terminate(Channel.java:992)
	at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer.onReadClosed(ChannelApplicationLayer.java:208)
	at org.jenkinsci.remoting.protocol.ApplicationLayer.onRecvClosed(ApplicationLayer.java:222)
	at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecvClosed(ProtocolStack.java:832)
	at org.jenkinsci.remoting.protocol.FilterLayer.onRecvClosed(FilterLayer.java:287)
	at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.onRecvClosed(SSLEngineFilterLayer.java:181)
	at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.switchToNoSecure(SSLEngineFilterLayer.java:283)
	at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processWrite(SSLEngineFilterLayer.java:503)
	at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processQueuedWrites(SSLEngineFilterLayer.java:248)
	at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doSend(SSLEngineFilterLayer.java:200)
	at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doCloseSend(SSLEngineFilterLayer.java:213)
	at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.doCloseSend(ProtocolStack.java:800)
	at org.jenkinsci.remoting.protocol.ApplicationLayer.doCloseWrite(ApplicationLayer.java:173)
	at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer$ByteBufferCommandTransport.closeWrite(ChannelApplicationLayer.java:311)
	at hudson.remoting.Channel.close(Channel.java:1405)
	at hudson.remoting.Channel.close(Channel.java:1358)
	at hudson.slaves.SlaveComputer.closeChannel(SlaveComputer.java:737)
	at hudson.slaves.SlaveComputer.access$800(SlaveComputer.java:96)
	at hudson.slaves.SlaveComputer$3.run(SlaveComputer.java:655)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

https://github.com/dotnet/core-eng/issues/2808
@dotnet/dnceng

@ahsonkhan ahsonkhan merged commit 9ff60da into dotnet:master Mar 2, 2018
@ahsonkhan ahsonkhan deleted the GetPosition branch March 2, 2018 04:09
@karelz karelz added this to the 2.1.0 milestone Mar 10, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Add GetPosition overload to ReadOnlySequence

* Address feedback (split tests)

* Use new GetPosition overload whenever passing start is redundant.


Commit migrated from dotnet/corefx@9ff60da
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants