@@ -48,6 +48,18 @@ use thiserror::Error;
48
48
pub ( crate ) type StmtCompiled =
49
49
Box < dyn for < ' v > Fn ( & mut Evaluator < ' v , ' _ > ) -> Result < ( ) , EvalException < ' v > > + Send + Sync > ;
50
50
51
+ pub ( crate ) enum StmtCompiledValue {
52
+ Compiled ( StmtCompiled ) ,
53
+ }
54
+
55
+ impl StmtCompiledValue {
56
+ pub ( crate ) fn as_compiled ( self ) -> StmtCompiled {
57
+ match self {
58
+ StmtCompiledValue :: Compiled ( c) => c,
59
+ }
60
+ }
61
+ }
62
+
51
63
enum SmallVec1 < T > {
52
64
Empty ,
53
65
One ( T ) ,
@@ -76,14 +88,14 @@ impl<T> SmallVec1<T> {
76
88
}
77
89
}
78
90
79
- pub ( crate ) struct StmtsCompiled ( SmallVec1 < StmtCompiled > ) ;
91
+ pub ( crate ) struct StmtsCompiled ( SmallVec1 < StmtCompiledValue > ) ;
80
92
81
93
impl StmtsCompiled {
82
94
pub ( crate ) fn empty ( ) -> StmtsCompiled {
83
95
StmtsCompiled ( SmallVec1 :: Empty )
84
96
}
85
97
86
- pub ( crate ) fn one ( stmt : StmtCompiled ) -> StmtsCompiled {
98
+ pub ( crate ) fn one ( stmt : StmtCompiledValue ) -> StmtsCompiled {
87
99
StmtsCompiled ( SmallVec1 :: One ( stmt) )
88
100
}
89
101
@@ -113,9 +125,10 @@ impl StmtsCompiled {
113
125
pub ( crate ) fn as_compiled ( self ) -> StmtCompiled {
114
126
match self . 0 {
115
127
SmallVec1 :: Empty => box |_eval| Ok ( ( ) ) ,
116
- SmallVec1 :: One ( stmt) => stmt,
128
+ SmallVec1 :: One ( stmt) => stmt. as_compiled ( ) ,
117
129
SmallVec1 :: Many ( vec) => {
118
130
debug_assert ! ( vec. len( ) > 1 ) ;
131
+ let vec = vec. into_map ( |s| s. as_compiled ( ) ) ;
119
132
box move |eval| {
120
133
for stmt in & vec {
121
134
stmt ( eval) ?;
@@ -413,10 +426,10 @@ impl Compiler<'_> {
413
426
assert ! ( stmt. len( ) == 1 ) ;
414
427
if self . has_before_stmt {
415
428
let stmt = stmt. as_compiled ( ) ;
416
- StmtsCompiled :: one ( box move |eval| {
429
+ StmtsCompiled :: one ( StmtCompiledValue :: Compiled ( box move |eval| {
417
430
before_stmt ( span, eval) ;
418
431
stmt ( eval)
419
- } )
432
+ } ) )
420
433
} else {
421
434
stmt
422
435
}
@@ -430,10 +443,10 @@ impl Compiler<'_> {
430
443
// We could do this more efficiently by fusing the possible_gc
431
444
// into the inner closure, but no real need - we insert allow_gc fairly rarely
432
445
let res = res. as_compiled ( ) ;
433
- StmtsCompiled :: one ( box move |eval| {
446
+ StmtsCompiled :: one ( StmtCompiledValue :: Compiled ( box move |eval| {
434
447
possible_gc ( eval) ;
435
448
res ( eval)
436
- } )
449
+ } ) )
437
450
} else {
438
451
res
439
452
}
0 commit comments