Optimize GC.AllocateUninitializedArray and use it in StringBuilder (dotnet/coreclr...
authorAdam Sitnik <adam.sitnik@gmail.com>
Thu, 24 Oct 2019 16:45:57 +0000 (18:45 +0200)
committerGitHub <noreply@github.com>
Thu, 24 Oct 2019 16:45:57 +0000 (18:45 +0200)
commitad387a865407120c49cc2f9664476ef38e56fdb7
tree2864fc74fbfffd94e54303cdf73f061ea64d5f82
parent9b3fb181d45be0ed547601cf4de3f0030eb99cc6
Optimize GC.AllocateUninitializedArray and use it in StringBuilder (dotnet/coreclr#27364)

* use GC.AllocateUninitializedArray for allocating internal char buffers

* force inlining of AllocateUninitializedArray to have no perf hit on the small buffers hot path

* insrease the threshold from 256 to 2048 bytes

* use Unsafe.As instead of a cast

* remove the size precondition from AllocateNewArray method, the called AllocateSzArray is responsible for handling negative size

Commit migrated from https://github.com/dotnet/coreclr/commit/c382edf50b2aadfc4f39d16fc53ea65ed35331e3
src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
src/coreclr/src/vm/comutilnative.cpp
src/coreclr/tests/src/GC/API/GC/AllocateUninitializedArray.cs
src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs