diff --git a/lib/rackstash/fields/abstract_collection.rb b/lib/rackstash/fields/abstract_collection.rb index 0d707de..c552cc8 100644 --- a/lib/rackstash/fields/abstract_collection.rb +++ b/lib/rackstash/fields/abstract_collection.rb @@ -115,7 +115,7 @@ module Rackstash when Rackstash::Fields::Hash, Rackstash::Fields::Array return wrap ? value : value.raw when ::Hash - hash = Concurrent::Hash.new + hash = {} value.each_pair do |k, v| hash[utf8_encode(k)] = normalize(v, scope: scope) end @@ -126,10 +126,7 @@ module Rackstash end return hash when ::Array, ::Set, ::Enumerator - array = Concurrent::Array.new - value.each do |e| - array << normalize(e, scope: scope) - end + array = value.map { |e| normalize(e, scope: scope) } if wrap array = Rackstash::Fields::Array.new.tap do |array_field| array_field.raw = array diff --git a/lib/rackstash/fields/array.rb b/lib/rackstash/fields/array.rb index d1955c5..55d8d7b 100644 --- a/lib/rackstash/fields/array.rb +++ b/lib/rackstash/fields/array.rb @@ -11,7 +11,7 @@ module Rackstash module Fields class Array < AbstractCollection def initialize - @raw = Concurrent::Array.new + @raw = [] end # @!method +(array) @@ -93,7 +93,7 @@ module Rackstash # start index is out of range def [](index, length = nil) result = length.nil? ? @raw[index] : @raw[index, length] - result = new(result) if ::Concurrent::Array === result + result = new(result) if ::Array === result result end alias slice [] @@ -167,7 +167,7 @@ module Rackstash # @return [::Array] deep-transforms the array into a plain Ruby Array def as_json(*) - @raw.to_a.map! { |value| + @raw.map { |value| value.is_a?(AbstractCollection) ? value.as_json : value } end diff --git a/lib/rackstash/fields/hash.rb b/lib/rackstash/fields/hash.rb index 8ae21c1..a7e8079 100644 --- a/lib/rackstash/fields/hash.rb +++ b/lib/rackstash/fields/hash.rb @@ -17,7 +17,7 @@ module Rackstash # @param forbidden_keys [Set,::Array] a list of strings # which are not allowed to be used as keys in this hash def initialize(forbidden_keys: EMPTY_SET) - @raw = Concurrent::Hash.new + @raw = {} unless forbidden_keys.is_a?(Set) && forbidden_keys.frozen? && @@ -62,7 +62,7 @@ module Rackstash # @return [::Hash] deep-transforms the hash into a plain Ruby Hash def as_json(*) - hash = @raw.to_h + hash = @raw.dup hash.each_pair do |key, value| hash[key] = value.as_json if value.is_a?(AbstractCollection) end diff --git a/lib/rackstash/fields/tags.rb b/lib/rackstash/fields/tags.rb index 25f48cf..94842bf 100644 --- a/lib/rackstash/fields/tags.rb +++ b/lib/rackstash/fields/tags.rb @@ -13,7 +13,7 @@ module Rackstash module Fields class Tags < AbstractCollection def initialize - @raw = Concurrent::Hash.new + @raw = {} end def <<(tag) diff --git a/spec/rackstash/fields/abstract_collection_spec.rb b/spec/rackstash/fields/abstract_collection_spec.rb index 843c5cd..18fd202 100644 --- a/spec/rackstash/fields/abstract_collection_spec.rb +++ b/spec/rackstash/fields/abstract_collection_spec.rb @@ -198,9 +198,9 @@ describe Rackstash::Fields::AbstractCollection do expect(normalize(hash, wrap: false).keys).to all be_frozen end - it 'returns a Concurrent::Hash with wrap: false' do + it 'returns a ::Hash with wrap: false' do hash = { 'one' => 1 } - expect(normalize(hash, wrap: false)).to be_an_instance_of(Concurrent::Hash) + expect(normalize(hash, wrap: false)).to be_an_instance_of(::Hash) end it 'normalizes all values' do @@ -267,9 +267,9 @@ describe Rackstash::Fields::AbstractCollection do expect(normalize(array, wrap: false)).to all be_frozen end - it 'returns a Concurrent::Array with wrap: false' do + it 'returns an ::Array with wrap: false' do array = [1, :two, 'three'] - expect(normalize(array, wrap: false)).to be_an_instance_of(Concurrent::Array) + expect(normalize(array, wrap: false)).to be_an_instance_of(::Array) end it 'normalizes all values' do