Skip to content

Commit

Permalink
Inline IdentifierExpr::compile_with_compiler in `IndexExpr::compile…
Browse files Browse the repository at this point in the history
…_with_compiler`

Other cases are already inline so this makes the code more consistent
and easier to reason about.
  • Loading branch information
marmeladema committed Feb 24, 2025
1 parent 02323c7 commit 638b84f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
16 changes: 1 addition & 15 deletions engine/src/ast/field_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{
use crate::{
ast::index_expr::IndexExpr,
compiler::Compiler,
filter::{CompiledExpr, CompiledValueExpr},
filter::CompiledExpr,
lex::{expect, skip_space, span, Lex, LexErrorKind, LexResult, LexWith},
range_set::RangeSet,
rhs_types::{Bytes, ExplicitIpRange, ListName, Regex, Wildcard},
Expand Down Expand Up @@ -241,20 +241,6 @@ pub enum IdentifierExpr<'s> {
FunctionCallExpr(FunctionCallExpr<'s>),
}

impl<'s> IdentifierExpr<'s> {
pub(crate) fn compile_with_compiler<C: Compiler<'s> + 's>(
self,
compiler: &mut C,
) -> CompiledValueExpr<'s, C::U> {
match self {
IdentifierExpr::Field(f) => {
CompiledValueExpr::new(move |ctx| Ok(ctx.get_field_value_unchecked(f).as_ref()))
}
IdentifierExpr::FunctionCallExpr(call) => compiler.compile_function_call_expr(call),
}
}
}

impl<'i, 's> LexWith<'i, &FilterParser<'s>> for IdentifierExpr<'s> {
fn lex_with(input: &'i str, parser: &FilterParser<'s>) -> LexResult<'i, Self> {
let (item, input) = Identifier::lex_with(input, parser.scheme)?;
Expand Down
7 changes: 6 additions & 1 deletion engine/src/ast/index_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ impl<'s> ValueExpr<'s> for IndexExpr<'s> {
};
if last == Some(0) {
// Fast path
identifier.compile_with_compiler(compiler)
match identifier {
IdentifierExpr::Field(f) => {
CompiledValueExpr::new(move |ctx| Ok(ctx.get_field_value_unchecked(f).as_ref()))
}
IdentifierExpr::FunctionCallExpr(call) => compiler.compile_function_call_expr(call),
}
} else if let Some(last) = last {
// Average path
match identifier {
Expand Down

0 comments on commit 638b84f

Please sign in to comment.