@@ -6,28 +6,59 @@ namespace HydraScript.Application.StaticAnalysis.Impl;
66
77internal class FunctionWithUndefinedReturnStorage : IFunctionWithUndefinedReturnStorage
88{
9+ #if NET10_0
910 private readonly OrderedDictionary < FunctionSymbolId , FunctionDeclaration > _declarations = [ ] ;
11+ #else
12+ private readonly Dictionary < FunctionSymbolId , FunctionDeclaration > _declarations = [ ] ;
13+ private readonly Dictionary < FunctionSymbolId , int > _keysWithOrder = [ ] ;
14+ #endif
1015
11- public void Save ( FunctionSymbol symbol , FunctionDeclaration declaration ) =>
16+ public void Save ( FunctionSymbol symbol , FunctionDeclaration declaration )
17+ {
1218 _declarations [ symbol . Id ] = declaration ;
19+ #if NET10_0
20+ #else
21+ _keysWithOrder [ symbol . Id ] = _declarations . Count ;
22+ #endif
23+ }
1324
1425 public FunctionDeclaration Get ( FunctionSymbol symbol )
1526 {
1627 if ( ! _declarations . Remove ( symbol . Id , out var declaration ) )
1728 throw new InvalidOperationException ( message : $ "Cannot get { symbol } that has not been saved") ;
18-
29+ #if NET10_0
30+ #else
31+ _keysWithOrder . Remove ( symbol . Id ) ;
32+ #endif
1933 return declaration ;
2034 }
2135
22- public void RemoveIfPresent ( FunctionSymbol symbol ) => _declarations . Remove ( symbol . Id ) ;
36+ public void RemoveIfPresent ( FunctionSymbol symbol )
37+ {
38+ _declarations . Remove ( symbol . Id ) ;
39+ #if NET10_0
40+ #else
41+ _keysWithOrder . Remove ( symbol . Id ) ;
42+ #endif
43+ }
2344
2445 public IEnumerable < FunctionDeclaration > Flush ( )
2546 {
47+ #if NET10_0
2648 IReadOnlyList < FunctionSymbolId > keys = _declarations . Keys ;
2749 while ( keys . Count > 0 )
2850 {
2951 yield return _declarations [ keys [ 0 ] ] ;
3052 _declarations . Remove ( keys [ 0 ] ) ;
3153 }
54+ #else
55+ return _declarations . OrderBy ( kvp => _keysWithOrder [ kvp . Key ] )
56+ . Select ( x =>
57+ {
58+ _declarations . Remove ( x . Key ) ;
59+ _keysWithOrder . Remove ( x . Key ) ;
60+ return x . Value ;
61+ } ) ;
62+ #endif
3263 }
3364}
0 commit comments