Skip to content

Commit 8baec0f

Browse files
committed
to_rust_cow_lossy
1 parent ac7fadc commit 8baec0f

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

src/binding.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,22 +1228,6 @@ void v8__String__ValueView__DESTRUCT(v8::String::ValueView* self) {
12281228
self->~ValueView();
12291229
}
12301230

1231-
bool v8__String__ValueView__is_one_byte(const v8::String::ValueView& self) {
1232-
return self.is_one_byte();
1233-
}
1234-
1235-
const void* v8__String__ValueView__data(const v8::String::ValueView& self) {
1236-
if (self.is_one_byte()) {
1237-
return reinterpret_cast<const void*>(self.data8());
1238-
} else {
1239-
return reinterpret_cast<const void*>(self.data16());
1240-
}
1241-
}
1242-
1243-
int v8__String__ValueView__length(const v8::String::ValueView& self) {
1244-
return self.length();
1245-
}
1246-
12471231
const v8::Symbol* v8__Symbol__New(v8::Isolate* isolate,
12481232
const v8::String* description) {
12491233
return local_to_ptr(v8::Symbol::New(isolate, ptr_to_local(description)));

src/string.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::String;
1010
use std::borrow::Cow;
1111
use std::convert::TryInto;
1212
use std::default::Default;
13+
use std::ffi::c_int;
1314
use std::ffi::c_void;
1415
use std::hint::unreachable_unchecked;
1516
use std::marker::PhantomData;
@@ -124,9 +125,14 @@ extern "C" {
124125
string: *const String,
125126
);
126127
fn v8__String__ValueView__DESTRUCT(this: *mut ValueView);
127-
fn v8__String__ValueView__is_one_byte(this: *const ValueView) -> bool;
128-
fn v8__String__ValueView__data(this: *const ValueView) -> *const c_void;
129-
fn v8__String__ValueView__length(this: *const ValueView) -> int;
128+
}
129+
130+
#[repr(C)]
131+
struct ValueViewRaw {
132+
flat_str: Local<'static, String>,
133+
data: *const c_void,
134+
length: c_int,
135+
is_one_byte: bool,
130136
}
131137

132138
#[derive(PartialEq, Debug)]
@@ -1170,12 +1176,18 @@ impl<'s> ValueView<'s> {
11701176
#[inline(always)]
11711177
pub fn data(&self) -> ValueViewData<'_> {
11721178
unsafe {
1173-
let data = v8__String__ValueView__data(self);
1174-
let length = v8__String__ValueView__length(self) as usize;
1175-
if v8__String__ValueView__is_one_byte(self) {
1176-
ValueViewData::OneByte(std::slice::from_raw_parts(data as _, length))
1179+
let this = &*(self as *const _ as *const ValueViewRaw);
1180+
let length = this.length as usize;
1181+
if this.is_one_byte {
1182+
ValueViewData::OneByte(std::slice::from_raw_parts(
1183+
this.data as _,
1184+
length,
1185+
))
11771186
} else {
1178-
ValueViewData::TwoByte(std::slice::from_raw_parts(data as _, length))
1187+
ValueViewData::TwoByte(std::slice::from_raw_parts(
1188+
this.data as _,
1189+
length,
1190+
))
11791191
}
11801192
}
11811193
}

0 commit comments

Comments
 (0)