Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Optimize Dir.glob #8081
This PR optimized
This is similar to how Python does it since some time ago and I can imagine Ruby does that too, probably other languages as well.
I just wanted to optimize this so the public API is still the same. I just exposed internally the information of whether a dir entry is a directory or not just for this purpose.
In the future we can consider whether it makes sense to expose this information in a public API but right now I'd like to avoid huge breaking changes, or having to think about new APIs. I think the change here is pretty straight-forward and small that it's not a big deal to introduce this optimization.
I wrote this benchmark:
require "benchmark" Benchmark.ips do |x| x.report("Dir.glob") do Dir.glob("*/*.cr") do end end end
RX14 left a comment •
This should really be exposed in the public API. This is really quite an especially ugly optimization.
Is this optimization worth rushing and not designing the API properly? I'm not sure. But I'm fine to approve it if an issue is created for adding the API to