提交 9c80f5b3 编写于 作者: A Aaron Patterson

use === to avoid regular expression creation, and speed up string comparison

上级 631b9564
...@@ -39,13 +39,7 @@ def wait ...@@ -39,13 +39,7 @@ def wait
class Binding #:nodoc: class Binding #:nodoc:
def initialize(queue, pattern) def initialize(queue, pattern)
@queue = queue @queue = queue
@pattern = @pattern = pattern
case pattern
when Regexp, NilClass
pattern
else
/^#{Regexp.escape(pattern.to_s)}$/
end
end end
def subscribe(&block) def subscribe(&block)
...@@ -70,13 +64,13 @@ def drained? ...@@ -70,13 +64,13 @@ def drained?
end end
def subscribed_to?(name) def subscribed_to?(name)
!@pattern || @pattern =~ name.to_s !@pattern || @pattern === name.to_s
end end
def matches?(subscriber_or_name) def matches?(subscriber_or_name)
case subscriber_or_name case subscriber_or_name
when String when String
@pattern && @pattern =~ subscriber_or_name @pattern && @pattern === subscriber_or_name
when self when self
true true
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册