mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-28 06:01:02 +00:00
Merge pull request #434 from Marwes/opt_memcpy
perf: Avoid some memcpying in reductions
This commit is contained in:
commit
fe75f44b4c
@ -610,17 +610,17 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
format!("_: {}", self.phantom_data_type()),
|
format!("_: {}", self.phantom_data_type()),
|
||||||
];
|
];
|
||||||
|
|
||||||
try!(
|
try!(self
|
||||||
self.out
|
.out
|
||||||
.fn_header(
|
.fn_header(
|
||||||
&Visibility::Priv,
|
&Visibility::Priv,
|
||||||
format!("{p}token_to_integer", p = self.prefix)
|
format!("{p}token_to_integer", p = self.prefix)
|
||||||
).with_type_parameters(&self.grammar.type_parameters)
|
)
|
||||||
.with_where_clauses(&self.grammar.where_clauses)
|
.with_type_parameters(&self.grammar.type_parameters)
|
||||||
.with_parameters(parameters)
|
.with_where_clauses(&self.grammar.where_clauses)
|
||||||
.with_return_type(format!("Option<usize>"))
|
.with_parameters(parameters)
|
||||||
.emit()
|
.with_return_type(format!("Option<usize>"))
|
||||||
);
|
.emit());
|
||||||
rust!(self.out, "{{");
|
rust!(self.out, "{{");
|
||||||
|
|
||||||
rust!(self.out, "match *{p}token {{", p = self.prefix);
|
rust!(self.out, "match *{p}token {{", p = self.prefix);
|
||||||
@ -660,17 +660,17 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
format!("_: {}", self.phantom_data_type()),
|
format!("_: {}", self.phantom_data_type()),
|
||||||
];
|
];
|
||||||
|
|
||||||
try!(
|
try!(self
|
||||||
self.out
|
.out
|
||||||
.fn_header(
|
.fn_header(
|
||||||
&Visibility::Priv,
|
&Visibility::Priv,
|
||||||
format!("{p}token_to_symbol", p = self.prefix),
|
format!("{p}token_to_symbol", p = self.prefix),
|
||||||
).with_type_parameters(&self.grammar.type_parameters)
|
)
|
||||||
.with_where_clauses(&self.grammar.where_clauses)
|
.with_type_parameters(&self.grammar.type_parameters)
|
||||||
.with_parameters(parameters)
|
.with_where_clauses(&self.grammar.where_clauses)
|
||||||
.with_return_type(symbol_type)
|
.with_parameters(parameters)
|
||||||
.emit()
|
.with_return_type(symbol_type)
|
||||||
);
|
.emit());
|
||||||
rust!(self.out, "{{");
|
rust!(self.out, "{{");
|
||||||
|
|
||||||
rust!(self.out, "match {p}token_index {{", p = self.prefix,);
|
rust!(self.out, "match {p}token_index {{", p = self.prefix,);
|
||||||
@ -733,23 +733,24 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
format!("_: {}", self.phantom_data_type()),
|
format!("_: {}", self.phantom_data_type()),
|
||||||
];
|
];
|
||||||
|
|
||||||
try!(
|
try!(self
|
||||||
self.out
|
.out
|
||||||
.fn_header(
|
.fn_header(
|
||||||
&Visibility::Pub(Some(Path::from_id(Atom::from("crate")))),
|
&Visibility::Pub(Some(Path::from_id(Atom::from("crate")))),
|
||||||
format!("{}reduce", self.prefix),
|
format!("{}reduce", self.prefix),
|
||||||
).with_grammar(self.grammar)
|
)
|
||||||
.with_parameters(parameters)
|
.with_grammar(self.grammar)
|
||||||
.with_return_type(format!(
|
.with_parameters(parameters)
|
||||||
"Option<Result<{},{}>>",
|
.with_return_type(format!(
|
||||||
success_type, parse_error_type
|
"Option<Result<{},{}>>",
|
||||||
)).emit()
|
success_type, parse_error_type
|
||||||
);
|
))
|
||||||
|
.emit());
|
||||||
rust!(self.out, "{{");
|
rust!(self.out, "{{");
|
||||||
|
|
||||||
rust!(
|
rust!(
|
||||||
self.out,
|
self.out,
|
||||||
"let ({p}pop_states, {p}symbol, {p}nonterminal) = match {}action {{",
|
"let ({p}pop_states, {p}nonterminal) = match {}action {{",
|
||||||
p = self.prefix
|
p = self.prefix
|
||||||
);
|
);
|
||||||
for (production, index) in self
|
for (production, index) in self
|
||||||
@ -806,8 +807,6 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
p = self.prefix
|
p = self.prefix
|
||||||
);
|
);
|
||||||
|
|
||||||
rust!(self.out, "{p}symbols.push({p}symbol);", p = self.prefix);
|
|
||||||
|
|
||||||
rust!(
|
rust!(
|
||||||
self.out,
|
self.out,
|
||||||
"let {}state = *{}states.last().unwrap() as usize;",
|
"let {}state = *{}states.last().unwrap() as usize;",
|
||||||
@ -879,16 +878,16 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
format!("_: {}", self.phantom_data_type()),
|
format!("_: {}", self.phantom_data_type()),
|
||||||
];
|
];
|
||||||
|
|
||||||
try!(
|
try!(self
|
||||||
self.out
|
.out
|
||||||
.fn_header(
|
.fn_header(
|
||||||
&Visibility::Pub(Some(Path::from_id(Atom::from("crate")))),
|
&Visibility::Pub(Some(Path::from_id(Atom::from("crate")))),
|
||||||
format!("{}reduce{}", self.prefix, index),
|
format!("{}reduce{}", self.prefix, index),
|
||||||
).with_grammar(self.grammar)
|
)
|
||||||
.with_parameters(parameters)
|
.with_grammar(self.grammar)
|
||||||
.with_return_type(format!("(usize, {}, usize)", spanned_symbol_type))
|
.with_parameters(parameters)
|
||||||
.emit()
|
.with_return_type(format!("(usize, usize)"))
|
||||||
);
|
.emit());
|
||||||
rust!(self.out, "{{");
|
rust!(self.out, "{{");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1004,7 +1003,7 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
self.variant_name_for_symbol(&Symbol::Nonterminal(production.nonterminal.clone()));
|
self.variant_name_for_symbol(&Symbol::Nonterminal(production.nonterminal.clone()));
|
||||||
rust!(
|
rust!(
|
||||||
self.out,
|
self.out,
|
||||||
"let {}symbol = ({}start, {}Symbol::{}({}nt), {}end);",
|
"{}symbols.push(({}start, {}Symbol::{}({}nt), {}end));",
|
||||||
self.prefix,
|
self.prefix,
|
||||||
self.prefix,
|
self.prefix,
|
||||||
self.prefix,
|
self.prefix,
|
||||||
@ -1023,8 +1022,7 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
rust!(
|
rust!(
|
||||||
self.out,
|
self.out,
|
||||||
"({len}, {p}symbol, {index})",
|
"({len}, {index})",
|
||||||
p = self.prefix,
|
|
||||||
index = index,
|
index = index,
|
||||||
len = production.symbols.len()
|
len = production.symbols.len()
|
||||||
);
|
);
|
||||||
@ -1106,20 +1104,21 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
format!("_: {}", self.phantom_data_type()),
|
format!("_: {}", self.phantom_data_type()),
|
||||||
];
|
];
|
||||||
|
|
||||||
try!(
|
try!(self
|
||||||
self.out
|
.out
|
||||||
.fn_header(
|
.fn_header(
|
||||||
&Visibility::Priv,
|
&Visibility::Priv,
|
||||||
format!("{p}simulate_reduce", p = self.prefix),
|
format!("{p}simulate_reduce", p = self.prefix),
|
||||||
).with_type_parameters(&self.custom.machine.type_parameters)
|
)
|
||||||
.with_where_clauses(&self.custom.machine.where_clauses)
|
.with_type_parameters(&self.custom.machine.type_parameters)
|
||||||
.with_parameters(parameters)
|
.with_where_clauses(&self.custom.machine.where_clauses)
|
||||||
.with_return_type(format!(
|
.with_parameters(parameters)
|
||||||
"{p}state_machine::SimulatedReduce<{p}StateMachine<{mtp}>>",
|
.with_return_type(format!(
|
||||||
p = self.prefix,
|
"{p}state_machine::SimulatedReduce<{p}StateMachine<{mtp}>>",
|
||||||
mtp = Sep(", ", &self.custom.machine.type_parameters),
|
p = self.prefix,
|
||||||
)).emit()
|
mtp = Sep(", ", &self.custom.machine.type_parameters),
|
||||||
);
|
))
|
||||||
|
.emit());
|
||||||
rust!(self.out, "{{");
|
rust!(self.out, "{{");
|
||||||
|
|
||||||
rust!(self.out, "match {p}reduce_index {{", p = self.prefix,);
|
rust!(self.out, "match {p}reduce_index {{", p = self.prefix,);
|
||||||
@ -1233,14 +1232,13 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TableDrive
|
|||||||
format!("_: {}", self.phantom_data_type()),
|
format!("_: {}", self.phantom_data_type()),
|
||||||
];
|
];
|
||||||
|
|
||||||
try!(
|
try!(self
|
||||||
self.out
|
.out
|
||||||
.fn_header(&Visibility::Priv, format!("{}accepts", self.prefix),)
|
.fn_header(&Visibility::Priv, format!("{}accepts", self.prefix),)
|
||||||
.with_grammar(self.grammar)
|
.with_grammar(self.grammar)
|
||||||
.with_parameters(parameters)
|
.with_parameters(parameters)
|
||||||
.with_return_type(format!("bool"))
|
.with_return_type(format!("bool"))
|
||||||
.emit()
|
.emit());
|
||||||
);
|
|
||||||
rust!(self.out, "{{");
|
rust!(self.out, "{{");
|
||||||
|
|
||||||
if DEBUG_PRINT {
|
if DEBUG_PRINT {
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user