@@ -17,6 +17,8 @@ private import Darwin
1717private import Glibc
1818#elseif canImport(Musl)
1919private import Musl
20+ #elseif canImport(CRT)
21+ private import CRT
2022#endif
2123#else
2224#if canImport(Darwin)
@@ -25,6 +27,8 @@ import Darwin
2527import Glibc
2628#elseif canImport(Musl)
2729import Musl
30+ #elseif canImport(CRT)
31+ import CRT
2832#endif
2933#endif
3034
@@ -131,7 +135,7 @@ public struct SyntaxText: Sendable {
131135 while start <= stop {
132136 // Force unwrappings are safe because we know 'self' and 'other' are both
133137 // not empty.
134- if compareMemory ( self . baseAddress! + start, other. baseAddress!, other. count) {
138+ if memcmp ( self . baseAddress! + start, other. baseAddress!, numericCast ( other. count) ) == 0 {
135139 return start..< ( start + other. count)
136140 } else {
137141 start += 1
@@ -194,11 +198,11 @@ extension SyntaxText: Hashable {
194198 // SwiftSyntax use cases, comparing the same SyntaxText instances is
195199 // extremely rare, and checking it causes extra branch.
196200 // 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
202206 }
203207
204208 /// Hash the contents of this ``SyntaxText`` into `hasher`.
@@ -270,19 +274,3 @@ extension String {
270274 }
271275 }
272276}
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