mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-13 09:33:02 -05:00
FastApiOneByteString is not always utf-8 (#1206)
This commit is contained in:
parent
a07c222ae3
commit
fe7610aa4a
2 changed files with 5 additions and 10 deletions
|
@ -218,14 +218,9 @@ pub struct FastApiOneByteString {
|
|||
|
||||
impl FastApiOneByteString {
|
||||
#[inline(always)]
|
||||
pub fn as_str(&self) -> &str {
|
||||
// SAFETY: The string is guaranteed to be valid UTF-8.
|
||||
unsafe {
|
||||
std::str::from_utf8_unchecked(std::slice::from_raw_parts(
|
||||
self.data,
|
||||
self.length as usize,
|
||||
))
|
||||
}
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
// SAFETY: The data is guaranteed to be valid for the length of the string.
|
||||
unsafe { std::slice::from_raw_parts(self.data, self.length as usize) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8915,8 +8915,8 @@ fn test_fast_calls_onebytestring() {
|
|||
data: *const fast_api::FastApiOneByteString,
|
||||
) -> u32 {
|
||||
unsafe { WHO = "fast" };
|
||||
let data = unsafe { &*data }.as_str();
|
||||
assert_eq!("hello", data);
|
||||
let data = unsafe { &*data }.as_bytes();
|
||||
assert_eq!(b"hello", data);
|
||||
data.len() as u32
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue