From 7eca1183250f85f8e08da9edf18d82486d2f3f35 Mon Sep 17 00:00:00 2001 From: Vakhid Betrakhmadov Date: Thu, 23 Jan 2025 16:10:04 +0000 Subject: [PATCH] Make hmaptool deterministic (#2637) Fix: #2636 --- tools/hmaptool/BinaryHeaderMapEncoder.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/hmaptool/BinaryHeaderMapEncoder.swift b/tools/hmaptool/BinaryHeaderMapEncoder.swift index 1eb77ec624..6cc9d7102e 100644 --- a/tools/hmaptool/BinaryHeaderMapEncoder.swift +++ b/tools/hmaptool/BinaryHeaderMapEncoder.swift @@ -18,14 +18,14 @@ public enum BinaryHeaderMapEncoder { static let encoding: String.Encoding = .utf8 public static func encode(_ headerMap: BinaryHeaderMap) throws -> Data { - let entries: [BinaryHeaderMap.Entry] = headerMap.entries.map { $0.value } + let entries: [BinaryHeaderMap.Entry] = headerMap.entries.map { $0.value }.sorted { $0.key < $1.key } return try makeHeaderMapBinaryData(withEntries: entries) } } private func makeHeaderMapBinaryData(withEntries unsafeEntries: [BinaryHeaderMap.Entry]) throws -> Data { let safeEntries = sanitize(headerEntries: unsafeEntries) - let allStrings = Set(safeEntries.flatMap { [$0.key, $0.prefix, $0.suffix] }) + let allStrings = Set(safeEntries.flatMap { [$0.key, $0.prefix, $0.suffix] }).sorted() let stringSection = try makeStringSection(allStrings: allStrings) let bucketSection = try makeBucketSection( forEntries: safeEntries, @@ -157,7 +157,7 @@ private struct StringSection { let offsets: [String: StringSectionOffset] } -private func makeStringSection(allStrings: Set) throws -> StringSection { +private func makeStringSection(allStrings: [String]) throws -> StringSection { var buffer = Data() var offsets: [String: StringSectionOffset] = [:]