Skip to content

Commit

Permalink
Iterator.empty patch
Browse files Browse the repository at this point in the history
  • Loading branch information
snichme committed Oct 1, 2024
1 parent 22659aa commit af69bfd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
10 changes: 0 additions & 10 deletions src/lavinmq/exchange.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
require "./exchange/*"

module LavinMQ
struct EmptyIterator(T)
include Iterator(T)

def next
stop
end
end
end
2 changes: 1 addition & 1 deletion src/lavinmq/exchange/consistent_hash.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module LavinMQ
if d = @hasher.get(key)
{d}.each
else
EmptyIterator(Destination).new
Iterator(Destination).empty
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/lavinmq/exchange/default.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ module LavinMQ
end

def bindings_details : Iterator(BindingDetails)
EmptyIterator(BindingDetails).new
Iterator(BindingDetails).empty
end

def bindings : Iterator(Destination)
EmptyIterator(Destination).new
Iterator(Destination).empty
end

protected def bindings(routing_key, headers) : Iterator(Destination)
if q = @vhost.queues[routing_key]?
Tuple(Destination).new(q).each
else
EmptyIterator(Destination).new
Iterator(Destination).empty
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/lavinmq/exchange/topic.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module LavinMQ
private def select_matches(routing_key) : Iterator(Destination)
binding_keys = @bindings

return EmptyIterator(Destination).new if binding_keys.empty?
return Iterator(Destination).empty if binding_keys.empty?

# optimize the case where the only binding key is '#'
if binding_keys.size == 1
Expand Down

0 comments on commit af69bfd

Please sign in to comment.