From 131807709aecd6a3ec0845cc90136db492c494eb Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Thu, 14 Nov 2024 19:33:26 +1100 Subject: [PATCH] Improve indexing performance by using .split instead of .components and using substrings instead of needlessly copying strings --- Sources/apk/Common/ApkRequirement.swift | 2 +- Sources/apk/Index/ApkIndexPackage.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/apk/Common/ApkRequirement.swift b/Sources/apk/Common/ApkRequirement.swift index 29f99d1..7fb0638 100644 --- a/Sources/apk/Common/ApkRequirement.swift +++ b/Sources/apk/Common/ApkRequirement.swift @@ -14,7 +14,7 @@ internal struct ApkRequirement: Hashable { self.versionSpec = spec } - init(extract: String) throws(ParseError) { + init(extract: Substring) throws(ParseError) { var comparer: ComparatorBits = [] var dependStr = extract[...] let nameEnd: String.Index, versionStart: String.Index diff --git a/Sources/apk/Index/ApkIndexPackage.swift b/Sources/apk/Index/ApkIndexPackage.swift index 1959637..3c5952c 100644 --- a/Sources/apk/Index/ApkIndexPackage.swift +++ b/Sources/apk/Index/ApkIndexPackage.swift @@ -75,7 +75,7 @@ extension ApkIndexPackage { architecture = record.value case "D": do { - dependencies = try record.value.components(separatedBy: " ") + dependencies = try record.value.split(separator: " ") .map { .init(requirement: try .init(extract: $0)) } } catch { throw .badValue(key: record.key) } case "C": @@ -95,12 +95,12 @@ extension ApkIndexPackage { installedSize = value case "p": do { - provides = try record.value.components(separatedBy: " ") + provides = try record.value.split(separator: " ") .map { .init(requirement: try .init(extract: $0)) } } catch { throw .badValue(key: record.key) } case "i": do { - installIf = try record.value.components(separatedBy: " ") + installIf = try record.value.split(separator: " ") .map { .init(requirement: try .init(extract: $0)) } } catch { throw .badValue(key: record.key) } case "o":