Skip to content

Commit dcdfda0

Browse files
committed
Reduce parser setup overhead.
1 parent e60a343 commit dcdfda0

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

lrpar/src/lib/parser.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub(super) struct Parser<
112112
{
113113
rcvry_kind: RecoveryKind,
114114
pub(super) grm: &'a YaccGrammar<StorageT>,
115-
pub(super) token_cost: Box<TokenCostFn<'a, StorageT>>,
115+
pub(super) token_cost: TokenCostFn<'a, StorageT>,
116116
pub(super) stable: &'a StateTable<StorageT>,
117117
lexer: &'b dyn NonStreamingLexer<'input, LexerTypesT>,
118118
// In the long term, we should remove the `lexemes` field entirely, as the `NonStreamingLexer` API is
@@ -176,7 +176,7 @@ where
176176
let psr = Parser {
177177
rcvry_kind,
178178
grm,
179-
token_cost: Box::new(token_cost),
179+
token_cost,
180180
stable,
181181
lexer,
182182
lexemes,
@@ -274,7 +274,7 @@ where
274274
let psr = Parser {
275275
rcvry_kind,
276276
grm,
277-
token_cost: Box::new(token_cost),
277+
token_cost,
278278
stable,
279279
lexer,
280280
lexemes,
@@ -970,13 +970,10 @@ where
970970
fterm: &dyn Fn(LexerTypesT::LexemeT) -> Node,
971971
fnonterm: &dyn Fn(RIdx<StorageT>, Vec<Node>) -> Node,
972972
) -> (Option<Node>, Vec<LexParseError<StorageT, LexerTypesT>>) {
973-
let mut lexemes = vec![];
974-
for e in lexer.iter().collect::<Vec<_>>() {
975-
match e {
976-
Ok(l) => lexemes.push(l),
977-
Err(e) => return (None, vec![e.into()]),
978-
}
979-
}
973+
let lexemes = match lexer.iter().collect() {
974+
Ok(lexemes) => lexemes,
975+
Err(e) => return (None, vec![e.into()]),
976+
};
980977
Parser::<
981978
StorageT,
982979
LexerTypesT,
@@ -1019,13 +1016,10 @@ where
10191016
actions: &'a [ActionFn<'a, 'b, 'input, StorageT, LexerTypesT, ActionT, ParamT>],
10201017
param: ParamT,
10211018
) -> (Option<ActionT>, Vec<LexParseError<StorageT, LexerTypesT>>) {
1022-
let mut lexemes = vec![];
1023-
for e in lexer.iter().collect::<Vec<_>>() {
1024-
match e {
1025-
Ok(l) => lexemes.push(l),
1026-
Err(e) => return (None, vec![e.into()]),
1027-
}
1028-
}
1019+
let lexemes = match lexer.iter().collect() {
1020+
Ok(lexemes) => lexemes,
1021+
Err(e) => return (None, vec![e.into()]),
1022+
};
10291023
Parser::parse_actions(
10301024
self.recoverer,
10311025
self.grm,

0 commit comments

Comments
 (0)