Closed Kestrer closed 4 years ago
This should indeed improve the performance. Although i'm not a fan of having unwrap
s in the codebase, i don't think it's possible to handle errors properly if we use the lazy_static
crate. Still should be ok because i don't expect to see undefined behaviour from a Regex::new
call.
Thanks for the PR!
unwrap
s are a very legit way to just express that the Result
/Option
are expected to contain Ok
/Some
. If they don't something very bad went wrong (Memory corruption?), so you kinda want it to crash then. Also when having constant parameters, you can expect unwrap
to never panic under normal circumstances, when it compiled initially.
Currently many of the
from_regex
functions recompile the regex each time they are called, which can be quite slow. This PR uses thelazy_static
crate to avoid this, by having the regexes become lazy-initialized and global.