Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 2862440

Browse files
committed
Faster Take
1 parent ada61f8 commit 2862440

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,23 @@ public bool IsEnd
5959

6060
public int Take()
6161
{
62-
if (_block == null)
62+
var block = _block;
63+
if (block == null)
6364
{
6465
return -1;
6566
}
66-
else if (_index < _block.End)
67+
68+
var index = _index;
69+
70+
if (index < block.End)
6771
{
68-
return _block.Array[_index++];
72+
_index = index + 1;
73+
return block.Array[index];
6974
}
7075

71-
var block = _block;
72-
var index = _index;
73-
while (true)
76+
do
7477
{
75-
if (index < block.End)
76-
{
77-
_block = block;
78-
_index = index + 1;
79-
return block.Array[index];
80-
}
81-
else if (block.Next == null)
78+
if (block.Next == null)
8279
{
8380
return -1;
8481
}
@@ -87,7 +84,15 @@ public int Take()
8784
block = block.Next;
8885
index = block.Start;
8986
}
90-
}
87+
88+
if (index < block.End)
89+
{
90+
_block = block;
91+
_index = index + 1;
92+
return block.Array[index];
93+
}
94+
95+
} while (true);
9196
}
9297

9398
public int Peek()

0 commit comments

Comments
 (0)