22use crate :: Op ;
33use pmutil:: { q, Quote } ;
44use proc_macro2:: TokenStream ;
5- use std:: collections:: HashMap ;
5+ use std:: collections:: BTreeMap ;
66use std:: fmt:: Debug ;
77use std:: fmt:: Formatter ;
88use syn:: {
99 parse_quote, punctuated:: Punctuated , token:: Colon2 ,
1010 AngleBracketedGenericArguments , FnArg , GenericArgument , PatType , Path ,
11- PathArguments , PathSegment , ReturnType , Signature , Type , TypePath ,
11+ PathArguments , PathSegment , ReturnType , Signature , Type , TypePath , TypePtr ,
1212 TypeReference , TypeSlice ,
1313} ;
1414
@@ -25,6 +25,7 @@ enum TransformKind {
2525 V8Value ,
2626 SliceU32 ( bool ) ,
2727 SliceU8 ( bool ) ,
28+ PtrU8 ,
2829}
2930
3031impl Transform {
@@ -48,6 +49,13 @@ impl Transform {
4849 index,
4950 }
5051 }
52+
53+ fn u8_ptr ( index : usize ) -> Self {
54+ Transform {
55+ kind : TransformKind :: PtrU8 ,
56+ index,
57+ }
58+ }
5159}
5260
5361#[ derive( Debug , PartialEq ) ]
@@ -116,6 +124,21 @@ impl Transform {
116124 } ;
117125 } )
118126 }
127+ // *const u8
128+ TransformKind :: PtrU8 => {
129+ * ty =
130+ parse_quote ! { * const #core:: v8:: fast_api:: FastApiTypedArray <u8 > } ;
131+
132+ q ! ( Vars { var: & ident } , {
133+ let var = match unsafe { & * var } . get_storage_if_aligned( ) {
134+ Some ( v) => v. as_ptr( ) ,
135+ None => {
136+ unsafe { & mut * fast_api_callback_options } . fallback = true ;
137+ return Default :: default ( ) ;
138+ }
139+ } ;
140+ } )
141+ }
119142 }
120143 }
121144}
@@ -178,7 +201,7 @@ pub(crate) struct Optimizer {
178201 pub ( crate ) fast_result : Option < FastValue > ,
179202 pub ( crate ) fast_parameters : Vec < FastValue > ,
180203
181- pub ( crate ) transforms : HashMap < usize , Transform > ,
204+ pub ( crate ) transforms : BTreeMap < usize , Transform > ,
182205 pub ( crate ) fast_compatible : bool ,
183206
184207 pub ( crate ) is_async : bool ,
@@ -517,6 +540,32 @@ impl Optimizer {
517540 } ,
518541 _ => return Err ( BailoutReason :: FastUnsupportedParamType ) ,
519542 } ,
543+ // *const T
544+ Type :: Ptr ( TypePtr {
545+ elem,
546+ const_token : Some ( _) ,
547+ ..
548+ } ) => match & * * elem {
549+ Type :: Path ( TypePath {
550+ path : Path { segments, .. } ,
551+ ..
552+ } ) => {
553+ let segment = single_segment ( segments) ?;
554+ match segment {
555+ // Is `T` a u8?
556+ PathSegment { ident, .. } if ident == "u8" => {
557+ self . has_fast_callback_option = true ;
558+ self . fast_parameters . push ( FastValue :: Uint8Array ) ;
559+ assert ! ( self
560+ . transforms
561+ . insert( index, Transform :: u8_ptr( index) )
562+ . is_none( ) ) ;
563+ }
564+ _ => return Err ( BailoutReason :: FastUnsupportedParamType ) ,
565+ }
566+ }
567+ _ => return Err ( BailoutReason :: FastUnsupportedParamType ) ,
568+ } ,
520569 _ => return Err ( BailoutReason :: FastUnsupportedParamType ) ,
521570 } ,
522571 _ => return Err ( BailoutReason :: FastUnsupportedParamType ) ,
0 commit comments