improve predicate lookup performance from .7 ms to .1 ms

Fixes #309
This commit is contained in:
Sean Linsley 2013-11-26 23:51:20 -06:00 committed by Ryan Bigg
parent af8895cab6
commit 98948773e4
1 changed files with 5 additions and 2 deletions

View File

@ -17,11 +17,14 @@ module Ransack
end
def detect_and_strip_from_string!(str)
names_by_decreasing_length.detect {|p| str.sub!(/_#{p}$/, '')}
if p = detect_from_string(str)
str.sub! /_#{p}$/, ''
p
end
end
def detect_from_string(str)
names_by_decreasing_length.detect {|p| str.match(/_#{p}$/)}
names_by_decreasing_length.detect {|p| str.end_with?("_#{p}")}
end
def name_from_attribute_name(attribute_name)