From d22a66f04eae856eb9157239005b87bc08af7e3c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 25 Oct 2024 06:17:43 +0900 Subject: [PATCH 1/2] WasmParser: Avoid using `indices.contains` in `ByteStream` The idiomatic way is semantically correct, but it's not the most efficient way. --- Sources/WasmParser/Stream/ByteStream.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/WasmParser/Stream/ByteStream.swift b/Sources/WasmParser/Stream/ByteStream.swift index 68590d65..612bb67e 100644 --- a/Sources/WasmParser/Stream/ByteStream.swift +++ b/Sources/WasmParser/Stream/ByteStream.swift @@ -16,7 +16,7 @@ public final class StaticByteStream: ByteStream { @discardableResult public func consumeAny() throws -> UInt8 { - guard bytes.indices.contains(currentIndex) else { + guard currentIndex < self.bytes.endIndex else { throw StreamError.unexpectedEnd(expected: nil) } @@ -27,7 +27,7 @@ public final class StaticByteStream: ByteStream { @discardableResult public func consume(_ expected: Set) throws -> UInt8 { - guard bytes.indices.contains(currentIndex) else { + guard currentIndex < self.bytes.endIndex else { throw StreamError.unexpectedEnd(expected: Set(expected)) } @@ -44,7 +44,7 @@ public final class StaticByteStream: ByteStream { guard count > 0 else { return [] } let updatedIndex = currentIndex + count - guard bytes.indices.contains(updatedIndex - 1) else { + guard updatedIndex - 1 < bytes.endIndex else { throw StreamError.unexpectedEnd(expected: nil) } @@ -54,7 +54,7 @@ public final class StaticByteStream: ByteStream { } public func peek() -> UInt8? { - guard bytes.indices.contains(currentIndex) else { + guard currentIndex < self.bytes.endIndex else { return nil } return bytes[currentIndex] From 27cca60dfd7502a51c2ebbceffc564315150599a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 25 Oct 2024 06:26:39 +0900 Subject: [PATCH 2/2] Utilities/format.py --- Tests/WITExtractorPluginTests/PluginSmokeTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/WITExtractorPluginTests/PluginSmokeTests.swift b/Tests/WITExtractorPluginTests/PluginSmokeTests.swift index bfaeef34..f7bc5bdb 100644 --- a/Tests/WITExtractorPluginTests/PluginSmokeTests.swift +++ b/Tests/WITExtractorPluginTests/PluginSmokeTests.swift @@ -3,7 +3,7 @@ import XCTest class PluginSmokeTests: XCTestCase { func testExtractPlugin() throws { #if compiler(>=6.0) - throw XCTSkip("XFAIL: Swift compiler path inference is broken in Swift 6.0") + throw XCTSkip("XFAIL: Swift compiler path inference is broken in Swift 6.0") #endif guard ProcessInfo.processInfo.environment["__XCODE_BUILT_PRODUCTS_DIR_PATHS"] == nil else { throw XCTSkip(