From ca24841d2e00c51a0a52df522139fcb096e0995f Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 27 Feb 2023 20:00:46 +0700 Subject: Use string.Create when available --- crypto/src/openpgp/SXprUtilities.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'crypto/src/openpgp') diff --git a/crypto/src/openpgp/SXprUtilities.cs b/crypto/src/openpgp/SXprUtilities.cs index d7969813f..835d3c347 100644 --- a/crypto/src/openpgp/SXprUtilities.cs +++ b/crypto/src/openpgp/SXprUtilities.cs @@ -34,6 +34,15 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { int len = ReadLength(input, ch); +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + return string.Create(len, input, (chars, input) => + { + for (int i = 0; i < chars.Length; ++i) + { + chars[i] = Convert.ToChar(input.ReadByte()); + } + }); +#else char[] chars = new char[len]; for (int i = 0; i != chars.Length; i++) @@ -42,6 +51,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp } return new string(chars); +#endif } internal static byte[] ReadBytes(Stream input, int ch) -- cgit 1.4.1