5 ms·
The usual way to use regular expressions in Rust is to use the Rust module that complies them at compile time. That can't be called from Go.
by Animats 11y ago
The usual way to use regular expressions in Rust is to use the Rust module that complies them at compile time. That can't be called from Go.
- burntsushi 11y agoUnfortunately, no, that is not the usual way any more. Two primary reasons: 1. Compiling regexes at compile time requires a compiler plugin, which only works on nightly. 2. The compile-time regexes are dramatically slower (think orders of magnitude) than the normal Regex::new method. The normal Regex::new method is what's shown here in these bindings. The compiler plugin was code I wrote two years ago, and really hasn't changed since then. Regex::new on the other hand has gotten a lot of love. The plugin's performance may one day get better, but it won't be soon unless someone else works on it.
- AYBABTME 11y agocurious, why is the compile-time regex slower? is it just a less efficient implementation?
- killercup 11y agoYes, several of the optimizations of the dynamic regexes aren't available in the compile-time version. (It doesn't even have a DFA, IIRC.) There is [a lint][1] which checks that your regular expressions are valid (at compile time), though. [1]: https://github.com/Manishearth/rust-clippy/wiki#invalid_regex https://github.com/Manishearth/rust-clippy/wiki#invalid_rege...
- burntsushi 11y agoRegex::new has these tools at its disposal: Pike VM (NFA), backtracking (NFA), DFA (online), DFA (offline), Boyer-Moore The plugin has these tools at its disposal: Pike VM. But yeah, killercup is correct. The DFA (online) is one of the bigger reasons. But the offline DFA and Boyer-Moore are probably just as important. You might glean more information from my hacking guide: https://github.com/rust-lang-nursery/regex/blob/master/HACKING.md https://github.com/rust-lang-nursery/regex/blob/master/HACKI...