From 73c4630246c0d789f3e2da94ec7398041cd483dd Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Fri, 15 Oct 2021 15:07:23 -0700 Subject: [PATCH] Atomic replace! --- lib/ddtrace/buffer.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/ddtrace/buffer.rb b/lib/ddtrace/buffer.rb index e83452f0d8..7933c1d5ed 100644 --- a/lib/ddtrace/buffer.rb +++ b/lib/ddtrace/buffer.rb @@ -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