From 98948773e48c7f33fc17aa22ce161ee88fdebf36 Mon Sep 17 00:00:00 2001 From: Sean Linsley Date: Tue, 26 Nov 2013 23:51:20 -0600 Subject: [PATCH] improve predicate lookup performance from .7 ms to .1 ms Fixes #309 --- lib/ransack/predicate.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ransack/predicate.rb b/lib/ransack/predicate.rb index a54e59b..23405fe 100644 --- a/lib/ransack/predicate.rb +++ b/lib/ransack/predicate.rb @@ -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)