Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ekump/remove 2.4 safe dup string code #3457

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -252,7 +251,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.

Loading