From 71b30778a0be495154ebd5bd5efd515f1c232fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Rebughini?= Date: Tue, 10 Jan 2023 15:01:18 +0100 Subject: [PATCH] Add frozen_string_literals magic comment This low effort change greatly changes the outcome of how many strings are allocated and, most importantly, retained by the gem. --- lib/analytics-ruby.rb | 2 ++ lib/segment.rb | 2 ++ lib/segment/analytics.rb | 2 ++ lib/segment/analytics/backoff_policy.rb | 2 ++ lib/segment/analytics/client.rb | 2 ++ lib/segment/analytics/defaults.rb | 2 ++ lib/segment/analytics/field_parser.rb | 2 ++ lib/segment/analytics/logging.rb | 2 ++ lib/segment/analytics/message_batch.rb | 2 ++ lib/segment/analytics/response.rb | 2 ++ lib/segment/analytics/test_queue.rb | 2 ++ lib/segment/analytics/transport.rb | 2 ++ lib/segment/analytics/utils.rb | 2 ++ lib/segment/analytics/version.rb | 2 ++ lib/segment/analytics/worker.rb | 2 ++ spec/isolated/json_example.rb | 2 ++ spec/isolated/with_active_support.rb | 2 ++ spec/isolated/with_active_support_and_oj.rb | 2 ++ spec/isolated/with_oj.rb | 2 ++ spec/segment/analytics/backoff_policy_spec.rb | 2 ++ spec/segment/analytics/client_spec.rb | 2 ++ spec/segment/analytics/message_batch_spec.rb | 2 ++ spec/segment/analytics/response_spec.rb | 2 ++ spec/segment/analytics/test_queue_spec.rb | 2 ++ spec/segment/analytics/transport_spec.rb | 2 ++ spec/segment/analytics/worker_spec.rb | 2 ++ spec/segment/analytics_spec.rb | 2 ++ spec/spec_helper.rb | 2 ++ 28 files changed, 56 insertions(+) diff --git a/lib/analytics-ruby.rb b/lib/analytics-ruby.rb index 801ad018..1c99ea1c 100644 --- a/lib/analytics-ruby.rb +++ b/lib/analytics-ruby.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'segment' diff --git a/lib/segment.rb b/lib/segment.rb index 1465165d..0efdd704 100644 --- a/lib/segment.rb +++ b/lib/segment.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'segment/analytics' diff --git a/lib/segment/analytics.rb b/lib/segment/analytics.rb index ca83353c..707e7c43 100644 --- a/lib/segment/analytics.rb +++ b/lib/segment/analytics.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'segment/analytics/version' require 'segment/analytics/defaults' require 'segment/analytics/utils' diff --git a/lib/segment/analytics/backoff_policy.rb b/lib/segment/analytics/backoff_policy.rb index 394a2c15..e6033b1f 100644 --- a/lib/segment/analytics/backoff_policy.rb +++ b/lib/segment/analytics/backoff_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'segment/analytics/defaults' module Segment diff --git a/lib/segment/analytics/client.rb b/lib/segment/analytics/client.rb index 9e626d9b..9589f69d 100644 --- a/lib/segment/analytics/client.rb +++ b/lib/segment/analytics/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'thread' require 'time' diff --git a/lib/segment/analytics/defaults.rb b/lib/segment/analytics/defaults.rb index 85623466..aa326974 100644 --- a/lib/segment/analytics/defaults.rb +++ b/lib/segment/analytics/defaults.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Segment class Analytics module Defaults diff --git a/lib/segment/analytics/field_parser.rb b/lib/segment/analytics/field_parser.rb index 602f4bbb..a7364ecd 100644 --- a/lib/segment/analytics/field_parser.rb +++ b/lib/segment/analytics/field_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Segment class Analytics # Handles parsing fields according to the Segment Spec diff --git a/lib/segment/analytics/logging.rb b/lib/segment/analytics/logging.rb index f7aaa636..5449878b 100644 --- a/lib/segment/analytics/logging.rb +++ b/lib/segment/analytics/logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'logger' module Segment diff --git a/lib/segment/analytics/message_batch.rb b/lib/segment/analytics/message_batch.rb index 1522463f..15eef433 100644 --- a/lib/segment/analytics/message_batch.rb +++ b/lib/segment/analytics/message_batch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'forwardable' require 'segment/analytics/logging' diff --git a/lib/segment/analytics/response.rb b/lib/segment/analytics/response.rb index 7306ac0a..c31116a6 100644 --- a/lib/segment/analytics/response.rb +++ b/lib/segment/analytics/response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Segment class Analytics class Response diff --git a/lib/segment/analytics/test_queue.rb b/lib/segment/analytics/test_queue.rb index af31558e..c93cad2f 100644 --- a/lib/segment/analytics/test_queue.rb +++ b/lib/segment/analytics/test_queue.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Segment class Analytics class TestQueue diff --git a/lib/segment/analytics/transport.rb b/lib/segment/analytics/transport.rb index 59697bea..6ee14d88 100644 --- a/lib/segment/analytics/transport.rb +++ b/lib/segment/analytics/transport.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'segment/analytics/defaults' require 'segment/analytics/utils' require 'segment/analytics/response' diff --git a/lib/segment/analytics/utils.rb b/lib/segment/analytics/utils.rb index 2c2d86a8..62ee69b0 100644 --- a/lib/segment/analytics/utils.rb +++ b/lib/segment/analytics/utils.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'securerandom' module Segment diff --git a/lib/segment/analytics/version.rb b/lib/segment/analytics/version.rb index c292749d..eaabbdf6 100644 --- a/lib/segment/analytics/version.rb +++ b/lib/segment/analytics/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Segment class Analytics VERSION = '2.4.2' diff --git a/lib/segment/analytics/worker.rb b/lib/segment/analytics/worker.rb index 7e73fae7..6a7d68e7 100644 --- a/lib/segment/analytics/worker.rb +++ b/lib/segment/analytics/worker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'segment/analytics/defaults' require 'segment/analytics/message_batch' require 'segment/analytics/transport' diff --git a/spec/isolated/json_example.rb b/spec/isolated/json_example.rb index c693b555..5f805338 100644 --- a/spec/isolated/json_example.rb +++ b/spec/isolated/json_example.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples 'message_batch_json' do it 'MessageBatch generates proper JSON' do batch = Segment::Analytics::MessageBatch.new(100) diff --git a/spec/isolated/with_active_support.rb b/spec/isolated/with_active_support.rb index 86178ae1..cfd9f2cb 100644 --- a/spec/isolated/with_active_support.rb +++ b/spec/isolated/with_active_support.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'isolated/json_example' diff --git a/spec/isolated/with_active_support_and_oj.rb b/spec/isolated/with_active_support_and_oj.rb index 18724e38..135be31b 100644 --- a/spec/isolated/with_active_support_and_oj.rb +++ b/spec/isolated/with_active_support_and_oj.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'isolated/json_example' diff --git a/spec/isolated/with_oj.rb b/spec/isolated/with_oj.rb index ad3f3762..7519238e 100644 --- a/spec/isolated/with_oj.rb +++ b/spec/isolated/with_oj.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'isolated/json_example' diff --git a/spec/segment/analytics/backoff_policy_spec.rb b/spec/segment/analytics/backoff_policy_spec.rb index 75dc9fce..25ef05ef 100644 --- a/spec/segment/analytics/backoff_policy_spec.rb +++ b/spec/segment/analytics/backoff_policy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics/client_spec.rb b/spec/segment/analytics/client_spec.rb index 0358bb2d..99c973b3 100644 --- a/spec/segment/analytics/client_spec.rb +++ b/spec/segment/analytics/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics/message_batch_spec.rb b/spec/segment/analytics/message_batch_spec.rb index 4b7b66fc..98f7be7e 100644 --- a/spec/segment/analytics/message_batch_spec.rb +++ b/spec/segment/analytics/message_batch_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics/response_spec.rb b/spec/segment/analytics/response_spec.rb index 7e099718..bb673dbf 100644 --- a/spec/segment/analytics/response_spec.rb +++ b/spec/segment/analytics/response_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics/test_queue_spec.rb b/spec/segment/analytics/test_queue_spec.rb index c97431d8..4aa4f77f 100644 --- a/spec/segment/analytics/test_queue_spec.rb +++ b/spec/segment/analytics/test_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics/transport_spec.rb b/spec/segment/analytics/transport_spec.rb index 56b551fe..b73ce9d6 100644 --- a/spec/segment/analytics/transport_spec.rb +++ b/spec/segment/analytics/transport_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics/worker_spec.rb b/spec/segment/analytics/worker_spec.rb index 0ca4d497..5111943a 100644 --- a/spec/segment/analytics/worker_spec.rb +++ b/spec/segment/analytics/worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/segment/analytics_spec.rb b/spec/segment/analytics_spec.rb index bf4dbedb..04431de6 100644 --- a/spec/segment/analytics_spec.rb +++ b/spec/segment/analytics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Segment diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a0f92476..b1d84358 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # https://github.com/codecov/codecov-ruby#usage require 'simplecov' SimpleCov.start