11using System . Collections ;
22using System . Runtime . CompilerServices ;
33
4- namespace HydraScript . Domain . FrontEnd . Parser . Impl . Ast
4+ namespace HydraScript . Domain . FrontEnd . Parser . Impl . Ast ;
5+
6+ /// <summary>
7+ /// Post in Telegram: https://t.me/csharp_gepard/89
8+ /// </summary>
9+ internal struct TraverseEnumerator :
10+ IEnumerator < IAbstractSyntaxTreeNode > ,
11+ IEnumerable < IAbstractSyntaxTreeNode >
512{
6- /// <summary>
7- /// Post in Telegram: https://t.me/csharp_gepard/89
8- /// </summary>
9- internal struct TraverseEnumerator :
10- IEnumerator < IAbstractSyntaxTreeNode > ,
11- IEnumerable < IAbstractSyntaxTreeNode >
13+ [ ThreadStatic ]
14+ private static Stack < IAbstractSyntaxTreeNode > ? _buffer ;
15+
16+ private IAbstractSyntaxTreeNode _current ;
17+
18+ public IAbstractSyntaxTreeNode Current
1219 {
13- [ ThreadStatic ] private static Stack < IAbstractSyntaxTreeNode > ? _buffer ;
14-
15- private IAbstractSyntaxTreeNode _current ;
16- public IAbstractSyntaxTreeNode Current
17- {
18- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
19- get => _current ;
20- }
21-
22- private readonly Stack < IAbstractSyntaxTreeNode > _stack ;
23- public TraverseEnumerator ( IAbstractSyntaxTreeNode parent )
24- {
25- var stack = _buffer ?? new Stack < IAbstractSyntaxTreeNode > ( 128 ) ;
26- _buffer = null ;
27-
28- for ( int i = 0 ; i < parent . Count ; i ++ )
29- stack . Push ( parent [ i ] ) ;
30-
31- _stack = stack ;
32- _current = null ! ;
33- }
34- public bool MoveNext ( )
35- {
36- var stack = _stack ;
37- if ( stack . Count == 0 )
38- return false ;
39-
40- var current = _stack . Pop ( ) ;
41-
42- for ( int i = 0 ; i < current . Count ; i ++ )
43- stack . Push ( current [ i ] ) ;
44-
45- _current = current ;
46- return true ;
47- }
48-
49- public void Dispose ( )
50- {
51- _stack . Clear ( ) ;
52- _buffer = _stack ;
53- }
54-
55- public void Reset ( ) { }
5620 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
57- public IEnumerator < IAbstractSyntaxTreeNode > GetEnumerator ( ) => this ;
21+ get => _current ;
22+ }
23+
24+ private readonly Stack < IAbstractSyntaxTreeNode > _stack ;
25+
26+ public TraverseEnumerator ( IAbstractSyntaxTreeNode parent )
27+ {
28+ var stack = _buffer ?? new Stack < IAbstractSyntaxTreeNode > ( 128 ) ;
29+ _buffer = null ;
30+
31+ for ( int i = 0 ; i < parent . Count ; i ++ )
32+ stack . Push ( parent [ i ] ) ;
33+
34+ _stack = stack ;
35+ _current = null ! ;
36+ }
37+
38+ public bool MoveNext ( )
39+ {
40+ var stack = _stack ;
41+ if ( stack . Count == 0 )
42+ return false ;
43+
44+ var current = _stack . Pop ( ) ;
45+
46+ for ( int i = 0 ; i < current . Count ; i ++ )
47+ stack . Push ( current [ i ] ) ;
5848
59- IEnumerator IEnumerable . GetEnumerator ( ) => this ;
49+ _current = current ;
50+ return true ;
51+ }
6052
61- object IEnumerator . Current => Current ;
53+ public void Dispose ( )
54+ {
55+ _stack . Clear ( ) ;
56+ _buffer = _stack ;
6257 }
63- }
58+
59+ public void Reset ( )
60+ {
61+ }
62+
63+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
64+ public IEnumerator < IAbstractSyntaxTreeNode > GetEnumerator ( ) => this ;
65+
66+ IEnumerator IEnumerable . GetEnumerator ( ) => this ;
67+
68+ object IEnumerator . Current => Current ;
69+ }
0 commit comments