Skip to content

Commit cac0e04

Browse files
committed
Reduce more Array object creations
1 parent b9fe288 commit cac0e04

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

actionpack/lib/action_dispatch/middleware/remote_ip.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def calculate_ip
159159

160160
# If every single IP option is in the trusted list, return the IP
161161
# that's furthest away
162-
filter_proxies(ips + [remote_addr]).first || ips.last || remote_addr
162+
ips.detect {|ip| @proxies.none? {|p| p === ip } } || (@proxies.none? {|p| p === remote_addr} && remote_addr) || ips.last || remote_addr
163163
end
164164

165165
# Memoizes the value returned by #calculate_ip and returns it for
@@ -183,12 +183,6 @@ def ips_from(header) # :doc:
183183
end
184184
ips
185185
end
186-
187-
def filter_proxies(ips) # :doc:
188-
ips.reject do |ip|
189-
@proxies.any? { |proxy| proxy === ip }
190-
end
191-
end
192186
end
193187
end
194188
end

0 commit comments

Comments
 (0)