Skip to content

Conversation

@atuchin-m
Copy link
Collaborator

@atuchin-m atuchin-m commented Dec 24, 2025

The PR replaces usages of once_cell crate to the standard std::sync:: primitives

@atuchin-m atuchin-m self-assigned this Dec 24, 2025
@atuchin-m atuchin-m requested a review from a team as a code owner December 24, 2025 16:19
static REPLACE_WILDCARDS: Lazy<Regex> = Lazy::new(|| Regex::new(r##"\*"##).unwrap());
static TRAILING_SEPARATOR: Lazy<Regex> = Lazy::new(|| Regex::new(r##"\^$"##).unwrap());
static SPECIAL_CHARS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r##"([.+?^${}()|\[\]\\])"##).unwrap());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[opengrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @kdenhartog

static SPECIAL_CHARS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r##"([.+?^${}()|\[\]\\])"##).unwrap());
static REPLACE_WILDCARDS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r##"\*"##).unwrap());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[opengrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @kdenhartog

static REPLACE_WILDCARDS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r##"\*"##).unwrap());
static TRAILING_SEPARATOR: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r##"\^$"##).unwrap());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[opengrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @kdenhartog

Lazy::new(|| Regex::new(r"^[#.]?[A-Za-z_][\w-]*$").unwrap());
use std::sync::LazyLock;
static RE_SIMPLE_SELECTOR: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[#.]?[A-Za-z_][\w-]*$").unwrap());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[opengrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @kdenhartog

// TODO - this could be made more efficient if we could match between two
// indices. Once again, we have to do more work than is really needed.
static SEPARATOR: Lazy<Regex> = Lazy::new(|| Regex::new("[/^*]").unwrap());
static SEPARATOR: LazyLock<Regex> = LazyLock::new(|| Regex::new("[/^*]").unwrap());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[opengrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @kdenhartog

static INVALID_CHARS: Lazy<Regex> =
Lazy::new(|| Regex::new("[/^*!?$&(){}\\[\\]+=~`\\s|@,'\"><:;]").unwrap());
static INVALID_CHARS: LazyLock<Regex> =
LazyLock::new(|| Regex::new("[/^*!?$&(){}\\[\\]+=~`\\s|@,'\"><:;]").unwrap());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[opengrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @kdenhartog

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Details
Benchmark suite Current: 762cf51 Previous: 501a190 Ratio
rule-match-browserlike/brave-list 2056135382 ns/iter (± 9214731) 2018520591 ns/iter (± 4934304) 1.02
rule-match-first-request/brave-list 1118974 ns/iter (± 5158) 1096986 ns/iter (± 15575) 1.02
blocker_new/brave-list 134715590 ns/iter (± 1333941) 131745302 ns/iter (± 313177) 1.02
blocker_new/brave-list-deserialize 23556301 ns/iter (± 328054) 22889579 ns/iter (± 85767) 1.03
memory-usage/brave-list-initial 10213344 ns/iter (± 3) 10213344 ns/iter (± 3) 1
memory-usage/brave-list-initial/max 60612235 ns/iter (± 3) 60612235 ns/iter (± 3) 1
memory-usage/brave-list-initial/alloc-count 996170 ns/iter (± 3) 996170 ns/iter (± 3) 1
memory-usage/brave-list-1000-requests 2282164 ns/iter (± 3) 2282164 ns/iter (± 3) 1
memory-usage/brave-list-1000-requests/alloc-count 69311 ns/iter (± 3) 69311 ns/iter (± 3) 1
url_cosmetic_resources/brave-list 194226 ns/iter (± 1344) 201294 ns/iter (± 495) 0.96
cosmetic-class-id-match/brave-list 3332694 ns/iter (± 924296) 3395590 ns/iter (± 898195) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@kdenhartog
Copy link
Member

Can we remove unwraps in non-test code?

@atuchin-m
Copy link
Collaborator Author

atuchin-m commented Jan 9, 2026

Can we remove unwraps in non-test code?

@kdenhartog this PR does straight forward API replacing without adding or removing unwrap().
Some of unwrap()/expect() is inevitable, i.e. see https://docs.rs/regex/latest/regex/
Anyway, the point is we need to so this in a dedicated PR. We have #432 for that.

@atuchin-m atuchin-m merged commit c7c016b into master Jan 16, 2026
9 checks passed
@atuchin-m atuchin-m deleted the replace-once_cell-to-std branch January 16, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants