Skip to content

Commit a132e1c

Browse files
authored
Merge pull request #17 from apple/string-equals
[LLVM] Add string equality operator
2 parents 7b137cc + c115d8c commit a132e1c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/LLVM/LLVM_Utils.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ extension StaticString {
2929
}
3030
}
3131

32+
public func ==(lhs: llvm.StringRef, rhs: StaticString) -> Bool {
33+
let lhsBuffer = UnsafeBufferPointer<UInt8>(
34+
start: lhs.__bytes_beginUnsafe(),
35+
count: Int(lhs.__bytes_endUnsafe() - lhs.__bytes_beginUnsafe()))
36+
return rhs.withUTF8Buffer { (rhsBuffer: UnsafeBufferPointer<UInt8>) in
37+
if lhsBuffer.count != rhsBuffer.count { return false }
38+
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
39+
}
40+
}
41+
3242
extension llvm.Twine: ExpressibleByStringLiteral {
3343
public init(stringLiteral value: String) {
3444
self.init(value)

0 commit comments

Comments
 (0)