@@ -17,6 +17,8 @@ private import Darwin
17
17
private import Glibc
18
18
#elseif canImport(Musl)
19
19
private import Musl
20
+ #elseif canImport(ucrt)
21
+ private import ucrt
20
22
#endif
21
23
#else
22
24
#if canImport(Darwin)
@@ -25,6 +27,8 @@ import Darwin
25
27
import Glibc
26
28
#elseif canImport(Musl)
27
29
import Musl
30
+ #elseif canImport(ucrt)
31
+ import ucrt
28
32
#endif
29
33
#endif
30
34
@@ -131,7 +135,7 @@ public struct SyntaxText: Sendable {
131
135
while start <= stop {
132
136
// Force unwrappings are safe because we know 'self' and 'other' are both
133
137
// not empty.
134
- if compareMemory ( self . baseAddress! + start, other. baseAddress!, other. count) {
138
+ if memcmp ( self . baseAddress! + start, other. baseAddress!, numericCast ( other. count) ) == 0 {
135
139
return start..< ( start + other. count)
136
140
} else {
137
141
start += 1
@@ -194,11 +198,11 @@ extension SyntaxText: Hashable {
194
198
// SwiftSyntax use cases, comparing the same SyntaxText instances is
195
199
// extremely rare, and checking it causes extra branch.
196
200
// The most common usage is comparing parsed text with a static text e.g.
197
- // `token.text == "func"`. In such cases `compareMemory`(` memcmp`) is
198
- // optimized to a `cmp` or similar opcode if either operand is a short static
199
- // text. So the same-baseAddress shortcut doesn't give us a huge performance
200
- // boost even if they actually refer the same memory.
201
- return compareMemory ( lBase, rBase, lhs. count)
201
+ // `token.text == "func"`. In such cases `memcmp` is optimized to a `cmp` or
202
+ // similar opcode if either operand is a short static text. So the
203
+ // same-baseAddress shortcut doesn't give us a huge performance boost even
204
+ // if they actually refer the same memory.
205
+ return memcmp ( lBase, rBase, numericCast ( lhs. count) ) == 0
202
206
}
203
207
204
208
/// Hash the contents of this ``SyntaxText`` into `hasher`.
@@ -270,19 +274,3 @@ extension String {
270
274
}
271
275
}
272
276
}
273
-
274
- private func compareMemory(
275
- _ s1: UnsafePointer < UInt8 > ,
276
- _ s2: UnsafePointer < UInt8 > ,
277
- _ count: Int
278
- ) -> Bool {
279
- precondition ( count >= 0 )
280
- #if canImport(Darwin)
281
- return Darwin . memcmp ( s1, s2, count) == 0
282
- #elseif canImport(Glibc)
283
- return Glibc . memcmp ( s1, s2, count) == 0
284
- #else
285
- return UnsafeBufferPointer ( start: s1, count: count)
286
- . elementsEqual ( UnsafeBufferPointer ( start: s2, count: count) )
287
- #endif
288
- }
0 commit comments