Auto merge of #113430 - Zalathar:hash, r=b-naber
Remove `LLVMRustCoverageHashCString` Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair (`LLVMRustCoverageHashByteArray`), and the other takes a NUL-terminated C string (`LLVMRustCoverageHashCString`). But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a `CString`, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it. So we can just call the ptr/len version directly instead. --- This PR also fixes a bug in the C++ declaration of `LLVMRustCoverageHashByteArray`. It should be `size_t`, since that's what is declared and passed on the Rust side, and it's what `StrRef`'s constructor expects to receive on the callee side.
This commit is contained in:
commit
ffb9b61294
4 changed files with 6 additions and 17 deletions
|
@ -373,12 +373,7 @@ pub(crate) fn write_mapping_to_buffer(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn hash_str(strval: &str) -> u64 {
|
||||
let strval = CString::new(strval).expect("null error converting hashable str to C string");
|
||||
unsafe { llvm::LLVMRustCoverageHashCString(strval.as_ptr()) }
|
||||
}
|
||||
|
||||
pub(crate) fn hash_bytes(bytes: Vec<u8>) -> u64 {
|
||||
pub(crate) fn hash_bytes(bytes: &[u8]) -> u64 {
|
||||
unsafe { llvm::LLVMRustCoverageHashByteArray(bytes.as_ptr().cast(), bytes.len()) }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue