From c2e467630fab447d3d9b30cc9dd3f8e24267f84e Mon Sep 17 00:00:00 2001 From: "Ivan A." Date: Sat, 15 Aug 2026 08:42:20 +0400 Subject: [PATCH 1/2] optimize empty string literal init --- Sources/InlineString/InlineString16.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/InlineString/InlineString16.swift b/Sources/InlineString/InlineString16.swift index 5da143c..594c800 100644 --- a/Sources/InlineString/InlineString16.swift +++ b/Sources/InlineString/InlineString16.swift @@ -261,6 +261,10 @@ extension InlineString16: ExpressibleByStringLiteral { /// As a result, the final UTF-8 byte of the string cannot be in the range `0x00...0x0F`, /// since those values are reserved for the length encoding. public init(stringLiteral value: StringLiteralType) { + guard !value.isEmpty else { + self.init() + return + } self.init(value) } } From 9682fcd45751542a3c4bb7fa9d27798903c47918 Mon Sep 17 00:00:00 2001 From: "Ivan A." Date: Sat, 15 Aug 2026 08:44:05 +0400 Subject: [PATCH 2/2] update benchmark results --- Benchmark.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Benchmark.md b/Benchmark.md index cd190de..84223d4 100644 --- a/Benchmark.md +++ b/Benchmark.md @@ -21,6 +21,7 @@ Differences within 1.00×–1.10× are treated as comparable performance. | `equality/different` | 1.112 | 1.112 | **comparable performance** | | `hash` | 7.545 | 7.557 | **comparable performance** | | `init/empty` | 1.112 | 1.112 | **comparable performance** | +| `init/empty/string-literal` | 1.112 | 1.113 | **comparable performance** | | `iterate/count` | 1.136 | 1.134 | **comparable performance** | | `decode/15-byte` | 374 | 376 | **comparable performance** | | `decode/16-byte` | 406 | 412 | **comparable performance** | @@ -31,6 +32,5 @@ Differences within 1.00×–1.10× are treated as comparable performance. | `encode/16-byte` | 367 | 394 | **comparable performance** | | `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** |