9
9
use std:: collections:: HashMap ;
10
10
use std:: fmt:: { self , Debug , Formatter } ;
11
11
12
- use smallvec:: { smallvec, SmallVec } ;
13
-
14
12
use crate :: syntax:: { TokenSeq , VariantIndex } ;
15
13
use crate :: text:: EncodingError ;
16
14
@@ -23,20 +21,20 @@ pub struct PrefixTable<T, O> {
23
21
#[ derive( Clone , Debug ) ]
24
22
pub enum PrefixEntry < O > {
25
23
Terminal ( O ) ,
26
- Prefix ( SmallVec < [ O ; 16 ] > ) ,
24
+ Prefix ( Vec < O > ) ,
27
25
}
28
26
29
27
#[ derive( Clone , Debug , PartialEq , Eq ) ]
30
28
pub struct ConflictError < T : VariantIndex , O > {
31
29
prefix : TokenSeq < T > ,
32
- opcodes : SmallVec < [ O ; 16 ] > ,
30
+ opcodes : Vec < O > ,
33
31
}
34
32
35
33
#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
36
34
pub enum PrefixError < T : VariantIndex , O > {
37
35
EncodingError ( EncodingError , TokenSeq < T > ) ,
38
36
UnknownOpcode ( TokenSeq < T > ) ,
39
- IncompleteOpcode ( TokenSeq < T > , SmallVec < [ O ; 16 ] > ) ,
37
+ IncompleteOpcode ( TokenSeq < T > , Vec < O > ) ,
40
38
}
41
39
42
40
impl < T , O > PrefixTable < T , O >
@@ -85,17 +83,17 @@ where
85
83
let entry = self . get_mut ( seq) ;
86
84
match entry {
87
85
Some ( PrefixEntry :: Terminal ( terminal) ) => {
88
- return Err ( ConflictError :: new ( seq, smallvec ! [ * terminal, opcode] ) ) ;
86
+ return Err ( ConflictError :: new ( seq, vec ! [ * terminal, opcode] ) ) ;
89
87
}
90
88
Some ( PrefixEntry :: Prefix ( opcodes) ) => opcodes. push ( opcode) ,
91
- None => * entry = Some ( PrefixEntry :: Prefix ( smallvec ! [ opcode] ) ) ,
89
+ None => * entry = Some ( PrefixEntry :: Prefix ( vec ! [ opcode] ) ) ,
92
90
}
93
91
seq. push ( tok) ;
94
92
}
95
93
let entry = self . get_mut ( seq) ;
96
94
match entry {
97
95
Some ( PrefixEntry :: Terminal ( terminal) ) => {
98
- return Err ( ConflictError :: new ( seq, smallvec ! [ * terminal, opcode] ) ) ;
96
+ return Err ( ConflictError :: new ( seq, vec ! [ * terminal, opcode] ) ) ;
99
97
}
100
98
Some ( PrefixEntry :: Prefix ( opcodes) ) => {
101
99
let mut opcodes = opcodes. clone ( ) ;
@@ -135,7 +133,7 @@ where
135
133
let prefix = match self . get ( seq) {
136
134
Some ( PrefixEntry :: Terminal ( opcode) ) => return Some ( Ok ( * opcode) ) ,
137
135
Some ( PrefixEntry :: Prefix ( opcodes) ) => opcodes. clone ( ) ,
138
- None => SmallVec :: new ( ) ,
136
+ None => Vec :: new ( ) ,
139
137
} ;
140
138
return Some ( Err ( PrefixError :: IncompleteOpcode ( seq, prefix) ) ) ;
141
139
}
@@ -200,7 +198,7 @@ where
200
198
impl < T : VariantIndex , O > ConflictError < T , O > {
201
199
#[ inline]
202
200
#[ must_use]
203
- const fn new ( prefix : TokenSeq < T > , opcodes : SmallVec < [ O ; 16 ] > ) -> Self {
201
+ const fn new ( prefix : TokenSeq < T > , opcodes : Vec < O > ) -> Self {
204
202
ConflictError { prefix, opcodes }
205
203
}
206
204
}
@@ -211,31 +209,3 @@ pub trait Tokens {
211
209
#[ must_use]
212
210
fn tokens ( & self ) -> & ' static [ Self :: Token ] ;
213
211
}
214
-
215
- #[ cfg( test) ]
216
- mod tests {
217
- use std:: mem:: size_of;
218
-
219
- use static_assertions:: { assert_eq_size, const_assert} ;
220
-
221
- use super :: * ;
222
- use crate :: ws:: inst:: Opcode ;
223
-
224
- #[ test]
225
- fn optimal_size ( ) {
226
- #[ allow( dead_code) ]
227
- enum PrefixEntryOf < T , P > {
228
- Terminal ( T ) ,
229
- Prefix ( P ) ,
230
- }
231
-
232
- assert_eq_size ! (
233
- PrefixEntry <Opcode >,
234
- Option <PrefixEntry <Opcode >>,
235
- PrefixEntryOf <Opcode , Vec <Opcode >>,
236
- PrefixEntryOf <Opcode , SmallVec <[ Opcode ; 16 ] >>,
237
- ) ;
238
- assert_eq_size ! ( Vec <Opcode >, SmallVec <[ Opcode ; 16 ] >) ;
239
- const_assert ! ( size_of:: <SmallVec <[ Opcode ; 16 ] >>( ) < size_of:: <SmallVec <[ Opcode ; 17 ] >>( ) ) ;
240
- }
241
- }
0 commit comments