Skip to content

Commit

Permalink
Ensure Path _str takes UTF-8 String fast paths
Browse files Browse the repository at this point in the history
Some clients (*cough* *cough* Xcode) like to create Paths out of bridged
NSStrings, which cannot be efficiently iterated. As most of our
operations require doing this frequently, we might as well convert on
construction to avoid the -characterAtIndex: slow path.
  • Loading branch information
saagarjha committed Feb 3, 2025
1 parent f7e63a3 commit 45b698e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/SWBUtil/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public struct Path: Serializable, Sendable {
}

public init(_ str: String) {
var str = str
str.makeContiguousUTF8()
self._str = str
}

Expand Down

0 comments on commit 45b698e

Please sign in to comment.