You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Perform a binary comparison of bytes in memory. Return value is negative if
// less, 0 if equal, positive if greater.
@_effects(readonly)internalfunc _binaryCompare<UInt8>(
_ lhs:UnsafeBufferPointer<UInt8>, _ rhs:UnsafeBufferPointer<UInt8>)->Int{varcmp=Int(truncatingIfNeeded:_swift_stdlib_memcmp(
lhs.baseAddress._unsafelyUnwrappedUnchecked,
rhs.baseAddress._unsafelyUnwrappedUnchecked,Swift.min(lhs.count, rhs.count)))
if cmp ==0{
cmp = lhs.count &- rhs.count
}return cmp
}
Low level enough to be good to implemented here, especially useful when comparing byte arrays that represent lexicographical keys.
Naive implementation:
Sneakier solution:
https://github.com/apple/swift/blob/aa3e5904f8ba8bf9ae06d96946774d171074f6e5/stdlib/public/core/StringComparison.swift#L280-L295
https://github.com/apple/swift/blob/aa3e5904f8ba8bf9ae06d96946774d171074f6e5/stdlib/public/SwiftShims/LibcShims.h#L70-L75
The text was updated successfully, but these errors were encountered: