Skip to content

Commit

Permalink
Atomic replace!
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Oct 15, 2021
1 parent b338281 commit 73c4630
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/ddtrace/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,9 @@ def replace!(item)
# `slice!` with a {Range} argument.
@items.slice!(@max_size, FIXNUM_MAX)

# we should replace a random trace with the new one
# We should replace a random trace with the new one
replace_index = rand(@items.size)
replaced_trace = @items.delete_at(replace_index)
@items << item

# We might have deleted an element right when the buffer
# was drained, thus +replaced_trace+ will be +nil+.
# In that case, nothing was replaced, and this method
# performed a simple insertion into the buffer.
replaced_trace
@items[replace_index] = item
end
end

Expand Down

0 comments on commit 73c4630

Please sign in to comment.