Skip to content

Commit 7aff243

Browse files
authored
improve TaskItem hashcode (#8988)
Tiny improvement to the hash code calculation perf - ItemSpec is just EscapingUtilities.UnescapeAll(_includeEscaped), which is a simple deterministic transform so we can just use the string. Added a comment to explain why we can't easily hash in something about the metadata. This means that all items with the same item spec continue to have the same hash code, which can cause degenerate performance.
1 parent abb6bbd commit 7aff243

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Build/Instance/ProjectItemInstance.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,11 @@ public override int GetHashCode()
14951495
// This is ignore case to ensure that task items whose item specs differ only by
14961496
// casing still have the same hash code, since this is used to determine if we have duplicates when
14971497
// we do duplicate removal.
1498-
return StringComparer.OrdinalIgnoreCase.GetHashCode(ItemSpec);
1498+
//
1499+
// Ideally this would also hash in something like the metadata count. However this requires calculation,
1500+
// because local and inherited metadata are equally considered during equality comparison, and the
1501+
// former may mask some of the latter.
1502+
return StringComparer.OrdinalIgnoreCase.GetHashCode(_includeEscaped);
14991503
}
15001504

15011505
/// <summary>

0 commit comments

Comments
 (0)