Skip to content

Commit

Permalink
Reduce allocations in AbstractTypeMap (#72588)
Browse files Browse the repository at this point in the history
Partial fix for #68996

Both SubstituteTypesWithoutModifiers and SubstituteNamedTypes allocate a temporary array that is used to potentially return an immutable array. Previously, this immutable array was allocated if needed, whereas we can not perform the extra allocation by utilizing ImmutableCollectionsMarshal as the array being wrapped is local to this method.
  • Loading branch information
ToddGrun authored Mar 19, 2024
1 parent 134bc2e commit 4880891
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Compilers/CSharp/Portable/Symbols/AbstractTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

Expand Down Expand Up @@ -313,7 +314,7 @@ internal ImmutableArray<TypeSymbol> SubstituteTypesWithoutModifiers(ImmutableArr
}
}

return result != null ? result.AsImmutableOrNull() : original;
return result != null ? ImmutableCollectionsMarshal.AsImmutableArray(result) : original;
}

internal ImmutableArray<TypeWithAnnotations> SubstituteTypes(ImmutableArray<TypeWithAnnotations> original)
Expand Down Expand Up @@ -430,7 +431,7 @@ internal ImmutableArray<NamedTypeSymbol> SubstituteNamedTypes(ImmutableArray<Nam
}
}

return result != null ? result.AsImmutableOrNull() : original;
return result != null ? ImmutableCollectionsMarshal.AsImmutableArray(result) : original;
}
}
}

0 comments on commit 4880891

Please sign in to comment.