@@ -10,6 +10,7 @@ use crate::String;
1010use std:: borrow:: Cow ;
1111use std:: convert:: TryInto ;
1212use std:: default:: Default ;
13+ use std:: ffi:: c_int;
1314use std:: ffi:: c_void;
1415use std:: hint:: unreachable_unchecked;
1516use 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