Coder Social home page Coder Social logo

Comments (6)

BurntSushi avatar BurntSushi commented on June 18, 2024

No, it's an implementation detail. It's not totally clear to me why your use case needs it to be public.

from ripgrep.

sxyazi avatar sxyazi commented on June 18, 2024

I want to know what kind of glob the user has set, such as whether it is just a simple extension glob. If it is, I can go through my own optimized processing logic without compiling a regular expression for it and performing regex matching, and only need to compare a small part of the path.

So I need to detect the type of glob the user has set and decide on a strategy, and I found that globset has implemented this very well just not make it public, of course I could refer to globset and re-implement it from scratch, but I think that's unnecessary workload.

from ripgrep.

sxyazi avatar sxyazi commented on June 18, 2024

Add more details:

After reading the source code of globset, I found that only GlobSet uses this strategy optimization during matching, while single glob matching (GlobMatcher) does not (please correct me if I'm wrong).

However, GlobSet::matches() matches all glob rules and then returns all indexes. For my needs (only needing to get the first matching icon), this is an unnecessary additional overhead because it could have ended early.

So what I need is a combination of strategy matching and early termination, which globset cannot provide since it uses strats: Vec<GlobSetMatchStrategy> to save each glob grouped according to the strategy, as the order between globs is no longer available, which is why it must calculate all the indexes and reorder them:

for strat in &self.strats {
strat.matches_into(path, into);
}
into.sort();
into.dedup();

Therefore, I think if the MatchStrategy is made public, I can implement it myself.

from ripgrep.

BurntSushi avatar BurntSushi commented on June 18, 2024

globset already avoids compiling a regex in some cases. Perhaps more cases could be added.

Sorry, but I don't want to expose internals like what you're requesting. I would be open to adding optimizations though.

from ripgrep.

sxyazi avatar sxyazi commented on June 18, 2024

OK no problem.

globset already avoids compiling a regex in some cases. Perhaps more cases could be added.

I couldn't find the relevant code, could you give me some hints? I'll see if I can add it - I'm interested in optimizing extension globs like *.jpg in GlobMatcher.

from ripgrep.

BurntSushi avatar BurntSushi commented on June 18, 2024

I'm confused because you are literally asking about the very thing that does what you want. It even has an optimization path for extensions.

match self.strategy {
MatchStrategy::Literal(ref lit) => lit.as_bytes() == byte_path,
MatchStrategy::BasenameLiteral(ref lit) => {
lit.as_bytes() == &*candidate.basename
}
MatchStrategy::Extension(ref ext) => {
ext.as_bytes() == &*candidate.ext
}
MatchStrategy::Prefix(ref pre) => {
starts_with(pre.as_bytes(), byte_path)
}
MatchStrategy::Suffix { ref suffix, component } => {
if component && byte_path == &suffix.as_bytes()[1..] {
return true;
}
ends_with(suffix.as_bytes(), byte_path)
}
MatchStrategy::RequiredExtension(ref ext) => {
let ext = ext.as_bytes();
&*candidate.ext == ext && self.re.is_match(byte_path)
}
MatchStrategy::Regex => self.re.is_match(byte_path),
}

It does not appear to skip compiling the regex, though, it does not use it for matching. I'd be open to adjustments that skip the regex compilation where possible. I can't remember whether that will be hard or not though. It could be a big refactor. But maybe not.

from ripgrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.