Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ DerivedData/
.netrc
Package.resolved

/Scripts/benchmarks
.benchmarkBaselines/
10 changes: 5 additions & 5 deletions Benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -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** |
Expand All @@ -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** |
4 changes: 4 additions & 0 deletions Sources/InlineString/InlineString16.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down