PERF: avoid regex for hot path

PERF: avoid regex for hot path

Camelize is called quite a lot in zeitwerk, avoid using a regex here which is far slower than using ends_with?

diff --git a/lib/freedom_patches/zeitwerk.rb b/lib/freedom_patches/zeitwerk.rb
index 4c68ede..9cd102a 100644
--- a/lib/freedom_patches/zeitwerk.rb
+++ b/lib/freedom_patches/zeitwerk.rb
@@ -18,8 +18,8 @@ module ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
   }
 
   def self.camelize(basename, abspath)
-    return basename.camelize if abspath =~ /onceoff\.rb$/
-    return 'Jobs' if abspath =~ /jobs\/base\.rb$/
+    return basename.camelize if abspath.ends_with?("onceoff.rb")
+    return 'Jobs' if abspath.ends_with?("jobs/base.rb")
     CUSTOM_PATHS.fetch(basename, basename.camelize)
   end
 end

GitHub sha: 586dfcc7

1 Like