Skip to content

Commit 83ad08c

Browse files
committed
optimized isSlice(of other: SyntaxText) -> Bool
1 parent f5d0a3a commit 83ad08c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/SwiftSyntax/SyntaxText.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ public struct SyntaxText {
100100
guard !self.isEmpty && !other.isEmpty else {
101101
return self.isEmpty && other.isEmpty
102102
}
103-
return (other.baseAddress! <= self.baseAddress! && self.baseAddress! + count <= other.baseAddress! + other.count)
103+
let first: Bool = other.baseAddress! <= self.baseAddress!
104+
let second = UnsafePointer<UInt8>(self.baseAddress! + count)
105+
let third = UnsafePointer<UInt8>(other.baseAddress! + other.count)
106+
return (first && second <= third)
104107
}
105108

106109
/// Returns `true` if `other` is a substring of this ``SyntaxText``.

0 commit comments

Comments
 (0)