Skip to content

Commit

Permalink
Use #clear to reset the buffer
Browse files Browse the repository at this point in the history
Avoid to assign new arrays all the time.
  • Loading branch information
weppos committed Sep 3, 2016
1 parent 5f87404 commit 1eec538
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions lib/whois/server/adapters/base.rb
Expand Up @@ -111,7 +111,7 @@ def configure(settings)
def lookup(string)
buffer_start do |buffer|
request(string)
Whois::Record.new(self, buffer)
Whois::Record.new(self, buffer.dup)
end
end

Expand Down Expand Up @@ -142,22 +142,15 @@ def query_handler

private

# Store a record part in {#buffer}.
#
# @param [String] body
# @param [String] host
# @return [void]
#
def buffer_append(body, host)
@buffer << Whois::Record::Part.new(:body => body, :host => host)
@buffer << Whois::Record::Part.new(body: body, host: host)
end

# @api private
def buffer_start
@buffer = []
result = yield(@buffer)
@buffer = [] # reset
result
@buffer ||= []
yield(@buffer)
ensure
@buffer.clear
end

# Prepares and passes the query to the {#query_handler}.
Expand Down

0 comments on commit 1eec538

Please sign in to comment.