@@ -217,32 +217,23 @@ public struct ExprTree
217217 /// <summary>Gets or sets owner-side metadata for block nodes, populated during FE construction.</summary>
218218 public SmallList < BlockInfo , Stack16 < BlockInfo > , NoArrayPool < BlockInfo > > Blocks ;
219219
220+ private SmallMap16 < int , int , IntEq > _lambdaInfoIndexesByNodeIndex ;
221+ private SmallMap16 < int , int , IntEq > _blockInfoIndexesByNodeIndex ;
222+
220223 /// <summary>Returns the owner-side metadata for the specified lambda node, if present.</summary>
221224 public bool TryGetLambdaInfo ( int lambdaIndex , out LambdaInfo info )
222225 {
223- for ( var i = 0 ; i < Lambdas . Count ; ++ i )
224- {
225- info = Lambdas . GetSurePresentRef ( i ) ;
226- if ( info . LambdaIndex == lambdaIndex )
227- return true ;
228- }
229-
230- info = default ;
231- return false ;
226+ ref var infoIndex = ref _lambdaInfoIndexesByNodeIndex . Map . TryGetValueRef ( lambdaIndex , out var found ) ;
227+ info = found ? Lambdas . GetSurePresentRef ( infoIndex ) : default ;
228+ return found ;
232229 }
233230
234231 /// <summary>Returns the owner-side metadata for the specified block node, if present.</summary>
235232 public bool TryGetBlockInfo ( int blockIndex , out BlockInfo info )
236233 {
237- for ( var i = 0 ; i < Blocks . Count ; ++ i )
238- {
239- info = Blocks . GetSurePresentRef ( i ) ;
240- if ( info . BlockIndex == blockIndex )
241- return true ;
242- }
243-
244- info = default ;
245- return false ;
234+ ref var infoIndex = ref _blockInfoIndexesByNodeIndex . Map . TryGetValueRef ( blockIndex , out var found ) ;
235+ info = found ? Blocks . GetSurePresentRef ( infoIndex ) : default ;
236+ return found ;
246237 }
247238
248239 /// <summary>Adds a parameter node and returns its index.</summary>
@@ -1368,12 +1359,32 @@ private void BindParameterDeclaration(int ownerIndex, int declarationIndex, int
13681359 }
13691360
13701361 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1371- private void AddLambdaInfo ( int lambdaIndex , int bodyIndex , in ChildList declarations ) =>
1372- Lambdas . Add ( new LambdaInfo ( lambdaIndex , bodyIndex , declarations ) ) ;
1362+ private void AddLambdaInfo ( int lambdaIndex , int bodyIndex , in ChildList declarations )
1363+ {
1364+ ref var infoIndex = ref _lambdaInfoIndexesByNodeIndex . Map . AddOrGetValueRef ( lambdaIndex , out var found ) ;
1365+ var info = new LambdaInfo ( lambdaIndex , bodyIndex , declarations ) ;
1366+ if ( found )
1367+ Lambdas . GetSurePresentRef ( infoIndex ) = info ;
1368+ else
1369+ {
1370+ infoIndex = Lambdas . Count ;
1371+ Lambdas . Add ( info ) ;
1372+ }
1373+ }
13731374
13741375 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1375- private void AddBlockInfo ( int blockIndex , int bodyExpressionsIndex , in ChildList declarations ) =>
1376- Blocks . Add ( new BlockInfo ( blockIndex , bodyExpressionsIndex , declarations ) ) ;
1376+ private void AddBlockInfo ( int blockIndex , int bodyExpressionsIndex , in ChildList declarations )
1377+ {
1378+ ref var infoIndex = ref _blockInfoIndexesByNodeIndex . Map . AddOrGetValueRef ( blockIndex , out var found ) ;
1379+ var info = new BlockInfo ( blockIndex , bodyExpressionsIndex , declarations ) ;
1380+ if ( found )
1381+ Blocks . GetSurePresentRef ( infoIndex ) = info ;
1382+ else
1383+ {
1384+ infoIndex = Blocks . Count ;
1385+ Blocks . Add ( info ) ;
1386+ }
1387+ }
13771388
13781389 private int AddParameterUsageNode ( in ExprNode node , int declarationIndex ) =>
13791390 AddRawLeafExpressionNode ( node . Type , node . Obj , ExpressionType . Parameter ,
0 commit comments