Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cfg-if = "1"
cidr = { version = "0.2", features = ["serde"] }
criterion = "0.5"
fnv = "1.0.6"
getrandom = { version = "0.3" }
indoc = "2"
libc = "0.2.42"
memmem = "0.1.1"
Expand Down
6 changes: 6 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ indoc.workspace = true
[features]
default = [ "regex" ]
regex = ["dep:regex-automata"]

[target.'cfg(target_family = "wasm")'.dependencies]
# By default, getrandom doesn't have any source of randomness on wasm32-unknown.
# This optional dependency allows us to build with `--features getrandom/wasm_js`.
# For more information see: https://docs.rs/getrandom/#webassembly-support
getrandom.workspace = true
10 changes: 7 additions & 3 deletions engine/src/ast/field_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,20 +655,24 @@ impl Expr for ComparisonExpr {
use rand::{Rng, rng};
use sliceslice::wasm32::*;

impl Compare<U> for Wasm32Searcher {
struct WasmSearcher(Wasm32Searcher<Box<[u8]>>);

impl<U> Compare<U> for WasmSearcher {
#[inline]
fn compare<'e>(
&self,
value: &LhsValue<'e>,
_: &'e ExecutionContext<'e, U>,
) -> bool {
self.search_in(cast_value!(value, Bytes))
unsafe { self.0.search_in(cast_value!(value, Bytes)) }
}
}

let position = rng().random_range(1..bytes.len());

return unsafe { search!(Wasm32Searcher::with_position(bytes, position)) };
return unsafe {
search!(WasmSearcher(Wasm32Searcher::with_position(bytes, position)))
};
}

search!(TwoWaySearcher::new(bytes))
Expand Down
Loading