Skip to content

Commit ad5675c

Browse files
committed
Eliminate the length check.
Minor performance improvement.
1 parent bfbf64f commit ad5675c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Renci.SshNet/Common/PipeStream.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public override int Read(byte[] buffer, int offset, int count)
195195
if (count == 0)
196196
return 0;
197197

198-
int readLength = 0;
198+
var readLength = 0;
199199

200200
lock (_buffer)
201201
{
@@ -211,7 +211,7 @@ public override int Read(byte[] buffer, int offset, int count)
211211
}
212212

213213
// fill the read buffer
214-
for (; readLength < count && Length > 0 && _buffer.Count > 0; readLength++)
214+
for (; readLength < count && _buffer.Count > 0; readLength++)
215215
{
216216
buffer[readLength] = _buffer.Dequeue();
217217
}
@@ -229,8 +229,8 @@ public override int Read(byte[] buffer, int offset, int count)
229229
/// <returns><c>True</c> if data available; otherwise<c>false</c>.</returns>
230230
private bool ReadAvailable(int count)
231231
{
232-
return (Length >= count || _isFlushed) &&
233-
(Length >= (count + 1) || !BlockLastReadBuffer);
232+
var length = Length;
233+
return (_isFlushed || length >= count) && (length >= (count + 1) || !BlockLastReadBuffer);
234234
}
235235

236236
///<summary>
@@ -267,7 +267,7 @@ public override void Write(byte[] buffer, int offset, int count)
267267
_isFlushed = false; // if it were flushed before, it soon will not be.
268268

269269
// queue up the buffer data
270-
for (int i = offset; i < offset + count; i++)
270+
for (var i = offset; i < offset + count; i++)
271271
{
272272
_buffer.Enqueue(buffer[i]);
273273
}

0 commit comments

Comments
 (0)