Skip to content

Commit e5eafbc

Browse files
committed
Runtime: Factor out GenericSignatureLayout::compare()
1 parent 864f5f0 commit e5eafbc

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

stdlib/public/runtime/MetadataCache.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ struct GenericSignatureLayout {
437437
const GenericSignatureLayout<Runtime> &rhs) {
438438
return !(lhs == rhs);
439439
}
440+
441+
int compare(const GenericSignatureLayout<Runtime> &rhs) const {
442+
if (auto result = compareIntegers(NumKeyParameters, rhs.NumKeyParameters))
443+
return result;
444+
445+
if (auto result = compareIntegers(NumWitnessTables, rhs.NumWitnessTables))
446+
return result;
447+
448+
return 0;
449+
}
440450
};
441451

442452
/// A key value as provided to the concurrent map.
@@ -521,7 +531,7 @@ class MetadataCacheKey {
521531
// Compare the hashes.
522532
if (hash() != rhs.hash()) return false;
523533

524-
// Compare the sizes.
534+
// Compare the layouts.
525535
if (Layout != rhs.Layout) return false;
526536

527537
// Compare the content.
@@ -530,23 +540,12 @@ class MetadataCacheKey {
530540

531541
int compare(const MetadataCacheKey &rhs) const {
532542
// Compare the hashes.
533-
if (auto hashComparison = compareIntegers(Hash, rhs.Hash)) {
534-
return hashComparison;
535-
}
536-
537-
// Compare the # of key parameters.
538-
if (auto keyParamsComparison =
539-
compareIntegers(Layout.NumKeyParameters,
540-
rhs.Layout.NumKeyParameters)) {
541-
return keyParamsComparison;
542-
}
543+
if (auto result = compareIntegers(Hash, rhs.Hash))
544+
return result;
543545

544-
// Compare the # of witness tables.
545-
if (auto witnessTablesComparison =
546-
compareIntegers(Layout.NumWitnessTables,
547-
rhs.Layout.NumWitnessTables)) {
548-
return witnessTablesComparison;
549-
}
546+
// Compare the layouts.
547+
if (auto result = Layout.compare(rhs.Layout))
548+
return result;
550549

551550
// Compare the content.
552551
return compareContent(begin(), rhs.begin(), Layout);

0 commit comments

Comments
 (0)