From 4def4acf257c28764aaba62962401cfb97b22fc2 Mon Sep 17 00:00:00 2001 From: zggsong Date: Tue, 5 Nov 2024 16:46:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=9B=B4=E6=96=B0id=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STranslateDLL/LocalMode.cs | 1 - STranslateDLL/Utilities.cs | 19 ++++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/STranslateDLL/LocalMode.cs b/STranslateDLL/LocalMode.cs index 2982804..02c0623 100644 --- a/STranslateDLL/LocalMode.cs +++ b/STranslateDLL/LocalMode.cs @@ -13,7 +13,6 @@ public static class LocalMode CancellationToken? token = null ) { - Utilities.Initial(); var getToken = token ?? CancellationToken.None; var splitResult = await SplitTextAsync(content, getToken); diff --git a/STranslateDLL/Utilities.cs b/STranslateDLL/Utilities.cs index ed58009..e6b9820 100644 --- a/STranslateDLL/Utilities.cs +++ b/STranslateDLL/Utilities.cs @@ -7,8 +7,6 @@ namespace STranslateDLL; public static class Utilities { public const string Url = "https://www2.deepl.com/jsonrpc"; - private static long _nextId; - private static bool _hasInit; public static readonly Dictionary TextTypeDic = new() { @@ -21,7 +19,7 @@ public static class Utilities { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault, - WriteIndented = true + // WriteIndented = true }; public static string Serialize(object data) @@ -29,17 +27,6 @@ public static class Utilities return JsonSerializer.Serialize(data, GetOptions); } - public static void Initial() - { - if (_hasInit) return; - - var rand = new Random(); - var number = rand.NextInt64(99999) + 8300000; - _nextId = number * 1000; - - _hasInit = true; - } - public static bool IsRichText(string text) { return text.Contains('<') && text.Contains('>'); @@ -54,7 +41,9 @@ public static class Utilities public static long CreateId() { - return Interlocked.Increment(ref _nextId); + var rand = new Random(); + var number = rand.NextInt64(99999) + 8300000; + return number * 1000; } public static string AdjustJsonContent(string json, long id)