comparison rust/hg-core/src/matchers.rs @ 44784:83c97c0bd319

rust-matchers: add timing tracing to regex compilation This might be useful to diagnose later performance issues or just to show the difference between engines. Differential Revision: https://phab.mercurial-scm.org/D8498
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 07 May 2020 10:10:13 +0200
parents e62052d0f377
children e0414fcd35e0
comparison
equal deleted inserted replaced
44778:cfe86fbc722e 44784:83c97c0bd319
28 use std::collections::HashSet; 28 use std::collections::HashSet;
29 use std::fmt::{Display, Error, Formatter}; 29 use std::fmt::{Display, Error, Formatter};
30 use std::iter::FromIterator; 30 use std::iter::FromIterator;
31 use std::ops::Deref; 31 use std::ops::Deref;
32 use std::path::{Path, PathBuf}; 32 use std::path::{Path, PathBuf};
33
34 use micro_timer::timed;
33 35
34 #[derive(Debug, PartialEq)] 36 #[derive(Debug, PartialEq)]
35 pub enum VisitChildrenSet<'a> { 37 pub enum VisitChildrenSet<'a> {
36 /// Don't visit anything 38 /// Don't visit anything
37 Empty, 39 Empty,
320 /// Returns a function that matches an `HgPath` against the given regex 322 /// Returns a function that matches an `HgPath` against the given regex
321 /// pattern. 323 /// pattern.
322 /// 324 ///
323 /// This can fail when the pattern is invalid or not supported by the 325 /// This can fail when the pattern is invalid or not supported by the
324 /// underlying engine `Re2`, for instance anything with back-references. 326 /// underlying engine `Re2`, for instance anything with back-references.
327 #[timed]
325 fn re_matcher( 328 fn re_matcher(
326 pattern: &[u8], 329 pattern: &[u8],
327 ) -> PatternResult<impl Fn(&HgPath) -> bool + Sync> { 330 ) -> PatternResult<impl Fn(&HgPath) -> bool + Sync> {
328 let regex = Re2::new(pattern); 331 let regex = Re2::new(pattern);
329 let regex = regex.map_err(|e| PatternError::UnsupportedSyntax(e))?; 332 let regex = regex.map_err(|e| PatternError::UnsupportedSyntax(e))?;
335 /// pattern. 338 /// pattern.
336 /// 339 ///
337 /// This can fail when the pattern is invalid or not supported by the 340 /// This can fail when the pattern is invalid or not supported by the
338 /// underlying engine (the `regex` crate), for instance anything with 341 /// underlying engine (the `regex` crate), for instance anything with
339 /// back-references. 342 /// back-references.
343 #[timed]
340 fn re_matcher( 344 fn re_matcher(
341 pattern: &[u8], 345 pattern: &[u8],
342 ) -> PatternResult<impl Fn(&HgPath) -> bool + Sync> { 346 ) -> PatternResult<impl Fn(&HgPath) -> bool + Sync> {
343 use std::io::Write; 347 use std::io::Write;
344 348