Performance fix for Pathname#chop_basename
This is an internal method, but is called a bunch of times in performance-critical codepaths, and is ultra slow because the constant is interpoplated into the Regexp each time the method is called. Alas, this has been fixed in Ruby 1.9+.
This commit is contained in:
parent
1bad199776
commit
5e9cfec8b8
@ -386,6 +386,18 @@ class Pathname
|
||||
end
|
||||
end
|
||||
|
||||
if RUBY_VERSION <= "1.8.7"
|
||||
alias_method :old_chop_basename, :chop_basename
|
||||
def chop_basename(path)
|
||||
base = File.basename(path)
|
||||
if /\A#{Pathname::SEPARATOR_PAT}?\z/o =~ base
|
||||
return nil
|
||||
else
|
||||
return path[0, path.rindex(base)], base
|
||||
end
|
||||
end
|
||||
private :chop_basename
|
||||
end
|
||||
end
|
||||
|
||||
# sets $n and $d so you can observe creation of stuff
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user