Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Improved wildcard matching performance #141

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.25.3"
version = "0.25.4-alpha.1"
edition = "2021"
build = "build.rs"

Expand Down Expand Up @@ -58,7 +58,7 @@ shellwords = "1"
signal-hook = "0"
snap = "1"
thiserror = "1"
wildmatch = "2"
wildflower = "0"
winapi = {version = "0", features = ["handleapi"]}
wyhash = "0"

Expand Down
16 changes: 7 additions & 9 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use json::value::RawValue;
use regex::Regex;
use serde::de::{Deserialize, Deserializer, MapAccess, SeqAccess, Visitor};
use serde_json as json;
use wildmatch::WildMatch;
use wildflower::Pattern;

// local imports
use crate::error::{Error, Result};
Expand Down Expand Up @@ -203,12 +203,12 @@ impl RecordFilter for RecordFilterNone {

// ---

#[derive(Default, Debug)]
#[derive(Default)]
pub struct ParserSettings {
pre_parse_time: bool,
level: Vec<HashMap<String, Level>>,
blocks: Vec<ParserSettingsBlock>,
ignore: Vec<WildMatch>,
ignore: Vec<Pattern<String>>,
}

impl ParserSettings {
Expand All @@ -221,7 +221,7 @@ impl ParserSettings {
pre_parse_time,
level: Vec::new(),
blocks: vec![ParserSettingsBlock::default()],
ignore: ignore.into_iter().map(|x| WildMatch::new(x)).collect(),
ignore: ignore.into_iter().map(|x| Pattern::new(x.to_string())).collect(),
};

result.init(predefined);
Expand Down Expand Up @@ -673,13 +673,12 @@ pub enum NumericOp {

// ---

#[derive(Debug)]
pub enum ValueMatchPolicy {
Exact(String),
SubString(String),
RegularExpression(Regex),
In(Vec<String>),
WildCard(WildMatch),
WildCard(Pattern<String>),
Numerically(NumericOp),
}

Expand Down Expand Up @@ -755,7 +754,6 @@ impl FieldFilterKey<String> {

// ---

#[derive(Debug)]
pub struct FieldFilter {
key: FieldFilterKey<String>,
match_policy: ValueMatchPolicy,
Expand Down Expand Up @@ -939,7 +937,7 @@ impl RecordFilter for FieldFilter {

// ---

#[derive(Debug, Default)]
#[derive(Default)]
pub struct FieldFilterSet(Vec<FieldFilter>);

impl FieldFilterSet {
Expand All @@ -961,7 +959,7 @@ impl RecordFilter for FieldFilterSet {

// ---

#[derive(Debug, Default)]
#[derive(Default)]
pub struct Filter {
pub fields: FieldFilterSet,
pub level: Option<Level>,
Expand Down
4 changes: 2 additions & 2 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use closure::closure;
use pest::{iterators::Pair, Parser};
use pest_derive::Parser;
use serde_json as json;
use wildmatch::WildMatch;
use wildflower::Pattern;

// local imports
use crate::error::Result;
Expand Down Expand Up @@ -120,7 +120,7 @@ fn field_filter(pair: Pair<Rule>) -> Result<Query> {
(ValueMatchPolicy::Exact(parse_string(rhs)?), op == Rule::op_not_equal)
}
(Rule::op_like | Rule::op_not_like, Rule::string) => (
ValueMatchPolicy::WildCard(WildMatch::new(parse_string(rhs)?.as_str())),
ValueMatchPolicy::WildCard(Pattern::new(parse_string(rhs)?.to_string())),
op == Rule::op_not_like,
),
(Rule::op_contain | Rule::op_not_contain, Rule::string) => (
Expand Down
Loading