File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -205,13 +205,15 @@ extension String {
205
205
206
206
extension Character : Equatable {
207
207
@inlinable @inline ( __always)
208
+ @_effects ( readonly)
208
209
public static func == ( lhs: Character , rhs: Character ) -> Bool {
209
210
return lhs. _str == rhs. _str
210
211
}
211
212
}
212
213
213
214
extension Character : Comparable {
214
215
@inlinable @inline ( __always)
216
+ @_effects ( readonly)
215
217
public static func < ( lhs: Character , rhs: Character ) -> Bool {
216
218
return lhs. _str < rhs. _str
217
219
}
Original file line number Diff line number Diff line change @@ -65,7 +65,11 @@ extension String {
65
65
@usableFromInline
66
66
internal static func _fromUTF8Repairing(
67
67
_ input: UnsafeBufferPointer < UInt8 >
68
- ) -> ( String , Bool ) {
68
+ ) -> ( result: String , repairsMade: Bool ) {
69
+ if _allASCII ( input) {
70
+ return ( String . _uncheckedFromUTF8 ( input, asciiPreScanResult: true ) , false )
71
+ }
72
+
69
73
// TODO(UTF8 perf): More efficient validation
70
74
71
75
// TODO(UTF8 perf): Skip intermediary array
@@ -95,6 +99,21 @@ extension String {
95
99
return storage. asString
96
100
}
97
101
102
+ // If we've already pre-scanned for ASCII, just supply the result
103
+ @usableFromInline
104
+ internal static func _uncheckedFromUTF8(
105
+ _ input: UnsafeBufferPointer < UInt8 > , asciiPreScanResult: Bool
106
+ ) -> String {
107
+ if let smol = _SmallString ( input) {
108
+ return String ( _StringGuts ( smol) )
109
+ }
110
+
111
+ let isASCII = asciiPreScanResult
112
+ let storage = _StringStorage. create (
113
+ initializingFrom: input, isASCII: isASCII)
114
+ return storage. asString
115
+ }
116
+
98
117
@usableFromInline
99
118
internal static func _uncheckedFromUTF16(
100
119
_ input: UnsafeBufferPointer < UInt16 >
You can’t perform that action at this time.
0 commit comments