This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
src/System.Collections/src/System/Collections/Generic Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -196,7 +196,10 @@ public void TrimExcess()
196196 public T Peek ( )
197197 {
198198 if ( _size == 0 )
199- throw new InvalidOperationException ( SR . InvalidOperation_EmptyStack ) ;
199+ {
200+ ThrowForEmptyStack ( ) ;
201+ }
202+
200203 return _array [ _size - 1 ] ;
201204 }
202205
@@ -216,7 +219,10 @@ public bool TryPeek(out T result)
216219 public T Pop ( )
217220 {
218221 if ( _size == 0 )
219- throw new InvalidOperationException ( SR . InvalidOperation_EmptyStack ) ;
222+ {
223+ ThrowForEmptyStack ( ) ;
224+ }
225+
220226 _version ++ ;
221227 T item = _array [ -- _size ] ;
222228 _array [ _size ] = default ( T ) ; // Free memory quicker.
@@ -264,6 +270,12 @@ public T[] ToArray()
264270 return objArray ;
265271 }
266272
273+ private void ThrowForEmptyStack ( )
274+ {
275+ Debug . Assert ( _size == 0 ) ;
276+ throw new InvalidOperationException ( SR . InvalidOperation_EmptyStack ) ;
277+ }
278+
267279 [ SuppressMessage ( "Microsoft.Performance" , "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes" , Justification = "not an expected scenario" ) ]
268280 [ Serializable ]
269281 public struct Enumerator : IEnumerator < T > , System . Collections . IEnumerator
You can’t perform that action at this time.
0 commit comments