Skip to content

Commit

Permalink
Add missing perf optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsensesoftware committed Nov 5, 2022
1 parent 80f8203 commit d4b6cfc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Common/src/Common/QueryStringApiVersionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Asp.Versioning;

#if !NETFRAMEWORK
using System.Buffers;
#endif
using static Asp.Versioning.ApiVersionParameterLocation;
using static System.StringComparer;

Expand Down Expand Up @@ -80,13 +83,22 @@ public virtual void AddParameters( IApiVersionParameterDescriptionContext contex
}

var count = ParameterNames.Count;
#if NETFRAMEWORK
var names = new string[count];
#else
var pool = ArrayPool<string>.Shared;
var names = pool.Rent( count );
#endif

ParameterNames.CopyTo( names, 0 );

for ( var i = 0; i < count; i++ )
{
context.AddParameter( names[i], Query );
}

#if !NETFRAMEWORK
pool.Return( names );
#endif
}
}

0 comments on commit d4b6cfc

Please sign in to comment.