Skip to content

Commit

Permalink
Merge pull request #3457 from DataDog/ekump/remove-2.4-safe-dup-strin…
Browse files Browse the repository at this point in the history
…g-code

ekump/remove 2.4 safe dup string code
  • Loading branch information
ekump authored Feb 13, 2024
2 parents 199cf2e + 00ee0a3 commit 976833f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 102 deletions.
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Metrics/BlockNesting:
Naming/FileName:
Exclude:
- 'lib/datadog/appsec/autoload.rb'
- 'lib/datadog/core/backport.rb'
- 'lib/datadog/opentelemetry/api/trace/span.rb'
- 'lib/datadog/opentelemetry/sdk/trace/span.rb'
- 'lib/datadog/profiling/load_native_extension.rb'
Expand Down
51 changes: 0 additions & 51 deletions lib/datadog/core/backport.rb

This file was deleted.

60 changes: 24 additions & 36 deletions lib/datadog/core/utils/safe_dup.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,37 @@
# frozen_string_literal: true

require_relative '../backport'

module Datadog
module Core
module Utils
# Helper methods for safer dup
module SafeDup
# String#+@ was introduced in Ruby 2.3
if String.method_defined?(:+@) && String.method_defined?(:-@)
def self.frozen_or_dup(v)
# For the case of a String we use the methods +@ and -@.
# Those methods are only for String objects
# they are faster and chepaer on the memory side.
# Check the benchmark on
# https://github.com/DataDog/dd-trace-rb/pull/2704
if v.is_a?(String)
# If the string is not frozen, the +(-v) will:
# - first create a frozen deduplicated copy with -v
# - then it will dup it more efficiently with +v
v.frozen? ? v : +(-v)
else
v.frozen? ? v : Core::BackportFrom24.dup(v)
end
end

def self.frozen_dup(v)
# For the case of a String we use the methods -@
# That method are only for String objects
# they are faster and chepaer on the memory side.
# Check the benchmark on
# https://github.com/DataDog/dd-trace-rb/pull/2704
if v.is_a?(String)
-v if v
else
v.frozen? ? v : Core::BackportFrom24.dup(v).freeze
end
end
else
def self.frozen_or_dup(v)
v.frozen? ? v : Core::BackportFrom24.dup(v)
def self.frozen_or_dup(v)
# For the case of a String we use the methods +@ and -@.
# Those methods are only for String objects
# they are faster and chepaer on the memory side.
# Check the benchmark on
# https://github.com/DataDog/dd-trace-rb/pull/2704
if v.is_a?(String)
# If the string is not frozen, the +(-v) will:
# - first create a frozen deduplicated copy with -v
# - then it will dup it more efficiently with +v
v.frozen? ? v : +(-v)
else
v.frozen? ? v : v.dup
end
end

def self.frozen_dup(v)
v.frozen? ? v : Core::BackportFrom24.dup(v).freeze
def self.frozen_dup(v)
# For the case of a String we use the methods -@
# That method are only for String objects
# they are faster and chepaer on the memory side.
# Check the benchmark on
# https://github.com/DataDog/dd-trace-rb/pull/2704
if v.is_a?(String)
-v if v
else
v.frozen? ? v : v.dup.freeze
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/datadog/tracing/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'date'

require_relative '../../../core/environment/variable_helpers'
require_relative '../../../core/backport'
require_relative '../../../core/remote/tie/tracing'
require_relative '../../client_ip'
require_relative '../../metadata/ext'
Expand Down Expand Up @@ -271,7 +270,7 @@ def parse_url(env, original_env)
else
# normally REQUEST_URI starts at the path, but it
# might contain the full URL in some cases (e.g WEBrick)
Datadog::Core::BackportFrom25.string_delete_prefix(request_uri, base_url)
request_uri.delete_prefix(base_url)
end

base_url + fullpath
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/sampling/rule_sampler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def self.parse(rules, rate_limit, default_sample_rate)
sample_rate: sample_rate,
}

Core::BackportFrom24.hash_compact!(kwargs)
kwargs.compact!

SimpleRule.new(**kwargs)
end
Expand Down
11 changes: 0 additions & 11 deletions sig/datadog/core/backport.rbs

This file was deleted.

0 comments on commit 976833f

Please sign in to comment.