@@ -441,30 +441,22 @@ public struct ResolvedTopicReference: Hashable, Codable, Equatable, CustomString
441
441
return url. absoluteString
442
442
}
443
443
444
- // Note: The source language of a `ResolvedTopicReference` is not considered when
445
- // hashing and checking for equality. This is intentional as DocC uses a single
446
- // ResolvedTopicReference to refer to all source language variants of a topic.
447
- //
448
- // This allows clients to look up topic references without knowing ahead of time
449
- // which languages they are available in.
450
-
451
444
public func hash( into hasher: inout Hasher ) {
452
- hasher. combine ( _storage. identifierPathAndFragment )
445
+ hasher. combine ( _storage)
453
446
}
454
447
455
448
public static func == ( lhs: ResolvedTopicReference , rhs: ResolvedTopicReference ) -> Bool {
456
- return lhs. _storage. identifierPathAndFragment == rhs. _storage. identifierPathAndFragment
449
+ return lhs. _storage == rhs. _storage
457
450
}
458
451
459
452
/// Storage for a resolved topic reference's state.
460
453
///
461
454
/// This is a reference type which allows ``ResolvedTopicReference`` to have copy-on-write behavior.
462
- class Storage {
455
+ class Storage : Hashable {
463
456
let bundleID : DocumentationBundle . Identifier
464
457
let path : String
465
458
let fragment : String ?
466
459
let sourceLanguages : Set < SourceLanguage >
467
- let identifierPathAndFragment : String
468
460
469
461
let url : URL
470
462
@@ -482,7 +474,6 @@ public struct ResolvedTopicReference: Hashable, Codable, Equatable, CustomString
482
474
self . path = path
483
475
self . fragment = fragment
484
476
self . sourceLanguages = sourceLanguages
485
- self . identifierPathAndFragment = " \( bundleID) \( path) \( fragment ?? " " ) "
486
477
487
478
var components = URLComponents ( )
488
479
components. scheme = ResolvedTopicReference . urlScheme
@@ -493,6 +484,28 @@ public struct ResolvedTopicReference: Hashable, Codable, Equatable, CustomString
493
484
self . pathComponents = self . url. pathComponents
494
485
self . absoluteString = self . url. absoluteString
495
486
}
487
+
488
+ // Note: The source language of a `ResolvedTopicReference` is not considered when
489
+ // hashing and checking for equality. This is intentional as DocC uses a single
490
+ // ResolvedTopicReference to refer to all source language variants of a topic.
491
+ //
492
+ // This allows clients to look up topic references without knowing ahead of time
493
+ // which languages they are available in.
494
+
495
+ func hash( into hasher: inout Hasher ) {
496
+ hasher. combine ( path)
497
+ hasher. combine ( fragment)
498
+ // Ignore the bundle ID in the hash even if it's used for equality (below).
499
+ // _Almost_ all content should be local, with the same bundle ID, so hashing it doesn't contribute to meaningful uniqueness
500
+ // and since the module name is already included in the path, paths very rarely collide across archives (where the bundle ID would help).
501
+ }
502
+
503
+ static func == ( lhs: Storage , rhs: Storage ) -> Bool {
504
+ lhs. path == rhs. path &&
505
+ lhs. fragment == rhs. fragment &&
506
+ lhs. bundleID == rhs. bundleID // Compare bundle ID last since it's expected to be the same for _almost_ all content in the build.
507
+
508
+ }
496
509
}
497
510
498
511
// For testing the caching
0 commit comments