Skip to content

Commit ca2d237

Browse files
jamesqostephentoub
authored andcommitted
Make Queue.Peek inline (dotnet/corefx#12062)
Commit migrated from dotnet/corefx@2d0e2ab
1 parent e8f23b7 commit ca2d237

File tree

1 file changed

+13
-3
lines changed
  • src/libraries/System.Collections/src/System/Collections/Generic

1 file changed

+13
-3
lines changed

src/libraries/System.Collections/src/System/Collections/Generic/Queue.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ IEnumerator IEnumerable.GetEnumerator()
228228
public T Dequeue()
229229
{
230230
if (_size == 0)
231-
throw new InvalidOperationException(SR.InvalidOperation_EmptyQueue);
231+
{
232+
ThrowForEmptyQueue();
233+
}
232234

233235
T removed = _array[_head];
234236
_array[_head] = default(T);
@@ -244,8 +246,10 @@ public T Dequeue()
244246
public T Peek()
245247
{
246248
if (_size == 0)
247-
throw new InvalidOperationException(SR.InvalidOperation_EmptyQueue);
248-
249+
{
250+
ThrowForEmptyQueue();
251+
}
252+
249253
return _array[_head];
250254
}
251255

@@ -328,6 +332,12 @@ private void MoveNext(ref int index)
328332
index = (tmp == _array.Length) ? 0 : tmp;
329333
}
330334

335+
private void ThrowForEmptyQueue()
336+
{
337+
Debug.Assert(_size == 0);
338+
throw new InvalidOperationException(SR.InvalidOperation_EmptyQueue);
339+
}
340+
331341
public void TrimExcess()
332342
{
333343
int threshold = (int)(((double)_array.Length) * 0.9);

0 commit comments

Comments
 (0)