From 5b18ed714b2e0afb359b872a79b96610c9015c33 Mon Sep 17 00:00:00 2001 From: PaulusParssinen Date: Tue, 30 Apr 2024 02:55:36 +0300 Subject: [PATCH] Hoist null check from loop in SortedSetObject.CopyDiff * Just fast-path copy the entire set if the other dictionary is null --- .../server/Objects/SortedSet/SortedSetObject.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/server/Objects/SortedSet/SortedSetObject.cs b/libs/server/Objects/SortedSet/SortedSetObject.cs index 49ba3de386..03225494d6 100644 --- a/libs/server/Objects/SortedSet/SortedSetObject.cs +++ b/libs/server/Objects/SortedSet/SortedSetObject.cs @@ -352,14 +352,17 @@ public override unsafe void Scan(long start, out List items, out long cu /// public static Dictionary CopyDiff(Dictionary dict1, Dictionary dict2) { - Dictionary result = new(); - if (dict1 != null) + if (dict1 == null) + return []; + + if (dict2 == null) + return new Dictionary(dict1); + + Dictionary result = []; + foreach (var item in dict1) { - foreach (var item in dict1) - { - if (dict2 == null || !dict2.ContainsKey(item.Key)) - result.Add(item.Key, item.Value); - } + if (!dict2.ContainsKey(item.Key)) + result.Add(item.Key, item.Value); } return result; }