From f76771e1b6195a838c6afd053fd48000ca579062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20G=C3=B6ls?= <6608231+Abrynos@users.noreply.github.com> Date: Fri, 22 Oct 2021 22:01:15 +0200 Subject: [PATCH] Use string.Create(...) instead of new string(...) (#2430) * Use string.Create(...) in MobileAuthenticator * Make it work in NETFRAMEWORK --- .../Steam/Security/MobileAuthenticator.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ArchiSteamFarm/Steam/Security/MobileAuthenticator.cs b/ArchiSteamFarm/Steam/Security/MobileAuthenticator.cs index 881333ea5..e40f72e69 100644 --- a/ArchiSteamFarm/Steam/Security/MobileAuthenticator.cs +++ b/ArchiSteamFarm/Steam/Security/MobileAuthenticator.cs @@ -19,6 +19,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if NETFRAMEWORK +using String = JustArchiNET.Madness.StringMadness.String; +#endif using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -390,14 +393,14 @@ namespace ArchiSteamFarm.Steam.Security { uint fullCode = BitConverter.ToUInt32(bytes, 0) & 0x7fffffff; // Build the alphanumeric code - char[] code = new char[CodeDigits]; - - for (byte i = 0; i < CodeDigits; i++) { - code[i] = CodeCharacters[(byte) (fullCode % CodeCharacters.Count)]; - fullCode /= (byte) CodeCharacters.Count; - } - - return new string(code); + return String.Create( + CodeDigits, fullCode, static (buffer, state) => { + for (byte i = 0; i < CodeDigits; i++) { + buffer[i] = CodeCharacters[(byte) (state % CodeCharacters.Count)]; + state /= (byte) CodeCharacters.Count; + } + } + ); } private async Task GetSteamTime() {