@@ -211,7 +211,7 @@ def process(cmd)
211211 emit = [ name , value ]
212212
213213 # add to table
214- if type == :incremental && size_check ( name . bytesize + value . bytesize + 32 )
214+ if type == :incremental && size_check? ( name . bytesize + value . bytesize + 32 )
215215 @table . unshift ( emit )
216216 @current_table_size += name . bytesize + value . bytesize + 32
217217 @_table_updated = true
@@ -302,7 +302,7 @@ def addcmd(field, value)
302302 # When the size is reduced, some headers might be evicted.
303303 def table_size = ( size )
304304 @limit = size
305- size_check ( 0 )
305+ resize_table ( 0 )
306306 end
307307
308308 def listen_on_table
@@ -313,22 +313,25 @@ def listen_on_table
313313
314314 private
315315
316+ def resize_table ( cmdsize )
317+ return if @table . empty?
318+
319+ while @current_table_size + cmdsize > @limit
320+
321+ name , value = @table . pop
322+ @current_table_size -= name . bytesize + value . bytesize + 32
323+ break if @table . empty?
324+
325+ end
326+ end
327+
316328 # To keep the dynamic table size lower than or equal to @limit,
317329 # remove one or more entries at the end of the dynamic table.
318330 #
319331 # @param cmdsize [Integer]
320332 # @return [Boolean] whether +cmd+ fits in the dynamic table.
321- def size_check ( cmdsize )
322- unless @table . empty?
323- while @current_table_size + cmdsize > @limit
324-
325- name , value = @table . pop
326- @current_table_size -= name . bytesize + value . bytesize + 32
327- break if @table . empty?
328-
329- end
330- end
331-
333+ def size_check? ( cmdsize )
334+ resize_table ( cmdsize )
332335 cmdsize <= @limit
333336 end
334337 end
0 commit comments