Skip to content

Commit 7eca118

Browse files
Make hmaptool deterministic (#2637)
Fix: #2636
1 parent 473ad0a commit 7eca118

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/hmaptool/BinaryHeaderMapEncoder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public enum BinaryHeaderMapEncoder {
1818
static let encoding: String.Encoding = .utf8
1919

2020
public static func encode(_ headerMap: BinaryHeaderMap) throws -> Data {
21-
let entries: [BinaryHeaderMap.Entry] = headerMap.entries.map { $0.value }
21+
let entries: [BinaryHeaderMap.Entry] = headerMap.entries.map { $0.value }.sorted { $0.key < $1.key }
2222
return try makeHeaderMapBinaryData(withEntries: entries)
2323
}
2424
}
2525

2626
private func makeHeaderMapBinaryData(withEntries unsafeEntries: [BinaryHeaderMap.Entry]) throws -> Data {
2727
let safeEntries = sanitize(headerEntries: unsafeEntries)
28-
let allStrings = Set(safeEntries.flatMap { [$0.key, $0.prefix, $0.suffix] })
28+
let allStrings = Set(safeEntries.flatMap { [$0.key, $0.prefix, $0.suffix] }).sorted()
2929
let stringSection = try makeStringSection(allStrings: allStrings)
3030
let bucketSection = try makeBucketSection(
3131
forEntries: safeEntries,
@@ -157,7 +157,7 @@ private struct StringSection {
157157
let offsets: [String: StringSectionOffset]
158158
}
159159

160-
private func makeStringSection(allStrings: Set<String>) throws -> StringSection {
160+
private func makeStringSection(allStrings: [String]) throws -> StringSection {
161161

162162
var buffer = Data()
163163
var offsets: [String: StringSectionOffset] = [:]

0 commit comments

Comments
 (0)