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?
This commit is contained in:
Sam Saffron 2019-10-08 13:43:54 +11:00
parent 7a5daa3079
commit 586dfcc795
1 changed files with 2 additions and 2 deletions

View File

@ -18,8 +18,8 @@ module ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
} }
def self.camelize(basename, abspath) def self.camelize(basename, abspath)
return basename.camelize if abspath =~ /onceoff\.rb$/ return basename.camelize if abspath.ends_with?("onceoff.rb")
return 'Jobs' if abspath =~ /jobs\/base\.rb$/ return 'Jobs' if abspath.ends_with?("jobs/base.rb")
CUSTOM_PATHS.fetch(basename, basename.camelize) CUSTOM_PATHS.fetch(basename, basename.camelize)
end end
end end