@@ -279,6 +279,34 @@ impl Bindings {
279279 }
280280}
281281
282+ fn single_external_borrowed_window (
283+ instrs : & [ Instr ] ,
284+ ) -> Option < ( ExternalFunctionId , Variable , usize , Variable ) > {
285+ match instrs {
286+ [
287+ Instr :: External {
288+ func,
289+ args,
290+ dst,
291+ } ,
292+ ] => {
293+ let mut start = None ;
294+ for ( idx, arg) in args. iter ( ) . enumerate ( ) {
295+ let QueryEntry :: Var ( v) = arg else {
296+ return None ;
297+ } ;
298+ if idx == 0 {
299+ start = Some ( * v) ;
300+ } else if v. index ( ) != start?. index ( ) + idx {
301+ return None ;
302+ }
303+ }
304+ start. map ( |start| ( * func, start, args. len ( ) , * dst) )
305+ }
306+ _ => None ,
307+ }
308+ }
309+
282310/// A binding that has been extracted from a [`Bindings`] struct via the [`Bindings::take`] method.
283311///
284312/// This allows for a variable's contents to be read while the [`Bindings`] struct has been
@@ -603,6 +631,33 @@ impl ExecutionState<'_> {
603631 bindings. matches = 1 ;
604632 }
605633
634+ if let Some ( ( func, start, len, dst) ) = single_external_borrowed_window ( instrs) {
635+ let matches = bindings. matches ;
636+ let mut out: Pooled < Vec < Value > > = with_pool_set ( |ps| ps. get ( ) ) ;
637+ out. resize ( matches, Value :: stale ( ) ) ;
638+ let mut transposed: Pooled < Vec < Value > > = with_pool_set ( |ps| ps. get ( ) ) ;
639+ transposed. resize ( matches * len, Value :: stale ( ) ) ;
640+ let start_index = start. index ( ) ;
641+ let mut succeeded = 0usize ;
642+ for row in 0 ..matches {
643+ for col in 0 ..len {
644+ transposed[ row * len + col] =
645+ bindings[ Variable :: from_usize ( start_index + col) ] [ row] ;
646+ }
647+ if self . should_stop ( ) {
648+ break ;
649+ }
650+ if let Some ( value) =
651+ self . call_external_func ( func, & transposed[ row * len..( row + 1 ) * len] )
652+ {
653+ out[ row] = value;
654+ succeeded += 1 ;
655+ }
656+ }
657+ bindings. insert ( dst, & out) ;
658+ return succeeded;
659+ }
660+
606661 // Vectorized execution for larger batch sizes
607662 let mut mask = with_pool_set ( |ps| Mask :: new ( 0 ..bindings. matches , ps) ) ;
608663 for instr in instrs {
0 commit comments