@@ -557,7 +557,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
557
557
key: ManifestCacheKey ,
558
558
cache: PersistentCacheProtocol
559
559
) throws -> ManifestParseResult {
560
- let keyHash = try key. computeHash ( )
560
+ let keyHash = ByteString ( encodingAsUTF8 : key. sha256Checksum )
561
561
let cacheHit = try keyHash. withData {
562
562
try cache. get ( key: $0)
563
563
} . flatMap {
@@ -588,6 +588,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
588
588
let toolsVersion : ToolsVersion
589
589
let env : [ String : String ]
590
590
let swiftpmVersion : String
591
+ let sha256Checksum : String
591
592
592
593
init ( packageIdentity: PackageIdentity ,
593
594
manifestPath: AbsolutePath ,
@@ -596,37 +597,38 @@ public final class ManifestLoader: ManifestLoaderProtocol {
596
597
swiftpmVersion: String ,
597
598
fileSystem: FileSystem
598
599
) throws {
600
+ let manifestContents = try fileSystem. readFileContents ( manifestPath) . contents
601
+ let sha256Checksum = try Self . computeSHA256Checksum ( packageIdentity: packageIdentity, manifestContents: manifestContents, toolsVersion: toolsVersion, env: env, swiftpmVersion: swiftpmVersion)
602
+
599
603
self . packageIdentity = packageIdentity
600
604
self . manifestPath = manifestPath
601
- self . manifestContents = try fileSystem . readFileContents ( manifestPath ) . contents
605
+ self . manifestContents = manifestContents
602
606
self . toolsVersion = toolsVersion
603
607
self . env = env
604
608
self . swiftpmVersion = swiftpmVersion
609
+ self . sha256Checksum = sha256Checksum
605
610
}
606
611
607
- // TODO: is there a way to avoid the dual hashing?
608
612
func hash( into hasher: inout Hasher ) {
609
- hasher. combine ( self . packageIdentity)
610
- hasher. combine ( self . manifestContents)
611
- hasher. combine ( self . toolsVersion. description)
612
- for key in self . env. keys. sorted ( by: > ) {
613
- hasher. combine ( key)
614
- hasher. combine ( env [ key] !)
615
- }
616
- hasher. combine ( self . swiftpmVersion)
613
+ hasher. combine ( self . sha256Checksum)
617
614
}
618
615
619
- // TODO: is there a way to avoid the dual hashing?
620
- func computeHash( ) throws -> ByteString {
616
+ private static func computeSHA256Checksum(
617
+ packageIdentity: PackageIdentity ,
618
+ manifestContents: [ UInt8 ] ,
619
+ toolsVersion: ToolsVersion ,
620
+ env: [ String : String ] ,
621
+ swiftpmVersion: String
622
+ ) throws -> String {
621
623
let stream = BufferedOutputByteStream ( )
622
- stream <<< self . packageIdentity
623
- stream <<< self . manifestContents
624
- stream <<< self . toolsVersion. description
625
- for key in self . env. keys. sorted ( by: > ) {
624
+ stream <<< packageIdentity
625
+ stream <<< manifestContents
626
+ stream <<< toolsVersion. description
627
+ for key in env. keys. sorted ( by: > ) {
626
628
stream <<< key <<< env [ key] !
627
629
}
628
- stream <<< self . swiftpmVersion
629
- return SHA256 ( ) . hash ( stream. bytes)
630
+ stream <<< swiftpmVersion
631
+ return stream. bytes. sha256Checksum
630
632
}
631
633
}
632
634
0 commit comments