Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoist null check from loop in SortedSetObject.CopyDiff #344

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions libs/server/Objects/SortedSet/SortedSetObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,17 @@ public override unsafe void Scan(long start, out List<byte[]> items, out long cu
/// </summary>
public static Dictionary<byte[], double> CopyDiff(Dictionary<byte[], double> dict1, Dictionary<byte[], double> dict2)
{
Dictionary<byte[], double> result = new();
if (dict1 != null)
if (dict1 == null)
return [];

if (dict2 == null)
return new Dictionary<byte[], double>(dict1);

Dictionary<byte[], double> 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;
}
Expand Down