diff --git a/.gitignore b/.gitignore index abc298b..088c37e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ DerivedData/ .netrc Package.resolved -/Scripts/benchmarks +.benchmarkBaselines/ diff --git a/Benchmark.md b/Benchmark.md index 3400a60..cd190de 100644 --- a/Benchmark.md +++ b/Benchmark.md @@ -10,8 +10,9 @@ Differences within 1.00×–1.10× are treated as comparable performance. | `copy/escaping/16-byte` | 1.778 | 0.669 | **2.66× faster** | | `search` | 3.865 | 1.601 | **2.41× faster** | | `iterate` | 2.445 | 1.113 | **2.20× faster** | +| `init/15-byte/string-literal` | 4.366 | 2.916 | **1.49× faster** | +| `init/15-byte` | 4.366 | 3.569 | **1.22× faster** | | `access/count(utf8)` | 1.334 | 1.112 | **1.20× faster** | -| `init/15-byte/string-literal` | 4.366 | 4.073 | **comparable performance** | | `decode/escaping/16-byte` | 403 | 398 | **comparable performance** | | `copy/empty` | 1.112 | 1.112 | **comparable performance** | | `copy/15-byte` | 1.112 | 1.112 | **comparable performance** | @@ -28,9 +29,8 @@ Differences within 1.00×–1.10× are treated as comparable performance. | `encode/escaping/16-byte` | 393 | 399 | **comparable performance** | | `decode/escaping/15-byte` | 378 | 403 | **comparable performance** | | `encode/16-byte` | 367 | 394 | **comparable performance** | -| `init/15-byte` | 4.366 | 5.431 | **1.24× slower** | -| `init/16-byte/string-literal` | 4.444 | 6.504 | **1.46× slower** | -| `init/16-byte` | 4.444 | 7.594 | **1.71× slower** | -| `init/empty/string-literal` | 1.112 | 3.316 | **2.98× slower** | +| `init/16-byte` | 4.444 | 4.734 | **comparable performance** | +| `init/16-byte/string-literal` | 4.444 | 4.268 | **comparable performance** | +| `init/empty/string-literal` | 1.112 | 2.902| **2.60× slower** | | `access/escaping/string` | 1.778 | 7.823 | **4.40× slower** | | `access/string` | 1.112 | 7.172 | **6.45× slower** | diff --git a/Sources/InlineString/InlineString16.swift b/Sources/InlineString/InlineString16.swift index f268d7f..5da143c 100644 --- a/Sources/InlineString/InlineString16.swift +++ b/Sources/InlineString/InlineString16.swift @@ -137,6 +137,7 @@ public struct InlineString16: BitwiseCopyable, Sendable { /// return `false` instead of triggering a runtime trap. /// - Returns: `true` if the string was successfully stored; otherwise, `false` /// when validation is enabled and the string exceeds the storage capacity. + @inline(__always) @discardableResult mutating func _initialize(from string: String, validating: Bool) -> Bool { guard !string.isEmpty else { @@ -167,6 +168,7 @@ public struct InlineString16: BitwiseCopyable, Sendable { /// - Parameters: /// - utf8: A UTF-8 view containing the bytes to copy. /// - storage: The destination storage tuple. + @inline(__always) mutating func _copyUTF8Bytes(from utf8: String.UTF8View) { precondition(utf8.count <= 15, "String must fit within small string capacity.") @@ -204,6 +206,7 @@ public struct InlineString16: BitwiseCopyable, Sendable { /// - Parameters: /// - string: The source string. /// - storage: The destination storage tuple. + @inline(__always) mutating func _copyStringContent(from string: String) { var string = string @@ -235,6 +238,7 @@ public struct InlineString16: BitwiseCopyable, Sendable { /// - Parameter validating: A Boolean value indicating whether the operation /// should fail gracefully instead of trapping. /// - Returns: `false` when validation is enabled. + @inline(__always) func _onExceedingCapacity(validating: Bool) -> Bool { if validating { return false