Skip to content
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
22 changes: 9 additions & 13 deletions src/Framework/ImmutableDictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal static class ImmutableDictionaryExtensions
public static readonly ImmutableDictionary<string, string> EmptyMetadata =
ImmutableDictionary<string, string>.Empty.WithComparers(MSBuildNameIgnoreCaseComparer.Default);

#if !TASKHOST
Comment thread
AR-May marked this conversation as resolved.
/// <summary>
/// Sets the given items while running a validation function on each key.
/// </summary>
Expand All @@ -29,23 +30,18 @@ public static ImmutableDictionary<string, string> SetItems(
IEnumerable<KeyValuePair<string, string>> items,
Action<string> verifyThrowKey)
{
return dictionary.SetItems(ValidateItems(items, verifyThrowKey));
ImmutableDictionary<string, string>.Builder builder = dictionary.ToBuilder();
Comment thread
ccastanedaucf marked this conversation as resolved.

// PERF: This extra allocation is still faster than enumerating ImmutableDictionary after modification.
static IEnumerable<KeyValuePair<string, string>> ValidateItems(
IEnumerable<KeyValuePair<string, string>> items,
Action<string> verifyThrowKey)
foreach (KeyValuePair<string, string> item in items)
{
foreach (KeyValuePair<string, string> item in items)
{
verifyThrowKey(item.Key);
verifyThrowKey(item.Key);

// Set null as empty string to match behavior with ProjectMetadataInstance.
yield return item.Value == null
? new KeyValuePair<string, string>(item.Key, string.Empty)
: item;
}
// Set null as empty string to match behavior with ProjectMetadataInstance.
builder[item.Key] = item.Value ?? string.Empty;
}

return builder.ToImmutable();
}
#endif
}
}