Use stackalloc in RSAPkcs1X509SignatureGenerator.BuildPublicKey (#46893)
authorStephen Toub <stoub@microsoft.com>
Wed, 13 Jan 2021 14:48:00 +0000 (09:48 -0500)
committerGitHub <noreply@github.com>
Wed, 13 Jan 2021 14:48:00 +0000 (09:48 -0500)
Just an unnecessary allocation.  The AsnEncodedData ctor makes a copy regardless of whether the input is a span or an array, so may as well avoid allocating another array on top of that.

src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/RSAPkcs1X509SignatureGenerator.cs

index ccfbe30..f49eb58 100644 (file)
@@ -39,7 +39,7 @@ namespace System.Security.Cryptography.X509Certificates
                 //
                 // This is due to one version of the ASN.1 not including OPTIONAL, and that was
                 // the version that got predominately implemented for RSA. Now it's convention.
-                new AsnEncodedData(oid, new byte[] { 0x05, 0x00 }),
+                new AsnEncodedData(oid, stackalloc byte[] { 0x05, 0x00 }),
                 new AsnEncodedData(oid, rsa.ExportRSAPublicKey()));
         }