From c7185fa3707d2edfb485cf8d6a60ae13afd9dc22 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Thu, 14 Nov 2024 20:58:04 +1100 Subject: [PATCH] Faster UTF8 decode --- Sources/apk/Index/ApkIndexUpdate.swift | 3 +-- Sources/apk/Utility/TextInputStream.swift | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/apk/Index/ApkIndexUpdate.swift b/Sources/apk/Index/ApkIndexUpdate.swift index 77a006d..3593833 100644 --- a/Sources/apk/Index/ApkIndexUpdate.swift +++ b/Sources/apk/Index/ApkIndexUpdate.swift @@ -103,9 +103,8 @@ public struct ApkIndexUpdater { print("Index time: \((ContinuousClock.now - indexStart).formatted(durFormat))") } - let reader = TextInputStream(binaryStream: MemoryInputStream(buffer: apkIndexFile)) return try ApkIndex(raw: - try ApkRawIndex(lines: reader.lines)) + try ApkRawIndex(lines: TextInputStream(binaryStream: MemoryInputStream(buffer: apkIndexFile)).lines)) } } diff --git a/Sources/apk/Utility/TextInputStream.swift b/Sources/apk/Utility/TextInputStream.swift index 8d83a11..0389542 100644 --- a/Sources/apk/Utility/TextInputStream.swift +++ b/Sources/apk/Utility/TextInputStream.swift @@ -74,7 +74,7 @@ struct TextInputStream where InStream.Element == UInt8 { if _fastPath(!self._bytes.isEmpty) { // Convert and return line - return String(bytes: self._bytes, encoding: .utf8) + return String(decoding: self._bytes, as: UTF8.self) } else { if _fastPath(!self._eof) { // Don't bother decoding empty lines and just return an empty string