1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

fix: fix bug introduced by d29663f081

Since value is a ref returned value, mutating it before returning was actually intended behaviour, since the reassignment causes the dictionary value to be mutated too.

Also, what game was this ref watching?!
This commit is contained in:
Oliver Booth 2023-04-01 22:31:54 +01:00
parent 9df0fde96d
commit 34c49a2228
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025

View File

@ -54,16 +54,7 @@ public static class DictionaryExtensions
#if NET6_0_OR_GREATER
ref var value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
if (exists)
{
value = updateValueFactory(key, value!);
}
else
{
value = addValue;
}
return value;
return value = exists ? updateValueFactory(key, value!) : addValue;
#else
if (dictionary.TryGetValue(key, out TValue? old))
{
@ -182,7 +173,7 @@ public static class DictionaryExtensions
#if NET6_0_OR_GREATER
ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
return exists ? updateValueFactory(key, value!) : addValueFactory(key);
return value = exists ? updateValueFactory(key, value!) : addValueFactory(key);
#else
if (dictionary.TryGetValue(key, out TValue? old))
{
@ -319,7 +310,7 @@ public static class DictionaryExtensions
#if NET6_0_OR_GREATER
ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
return exists ? updateValueFactory(key, value!, factoryArgument) : addValueFactory(key, factoryArgument);
return value = exists ? updateValueFactory(key, value!, factoryArgument) : addValueFactory(key, factoryArgument);
#else
if (dictionary.TryGetValue(key, out TValue? old))
{