From bed879ce07bc8b7080d128de43db69065cee66df Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Thu, 10 Nov 2022 20:38:40 -0300 Subject: [PATCH 1/2] Sort keys without block in CSV.instance ``DEFAULT_OPTIONS`` is a frozen Hash with symbols as keys. There is no need to convert such keys to strings before sorting. Note that sorting is not needed for stable implementations of Hash, keys would always be returned in the same entry order. We could remove sorting if every supported Ruby implements entry order Hashes. --- lib/csv.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/csv.rb b/lib/csv.rb index 20270cb8..8ef94ce3 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1005,7 +1005,7 @@ class << self def instance(data = $stdout, **options) # create a _signature_ for this method call, data object and options sig = [data.object_id] + - options.values_at(*DEFAULT_OPTIONS.keys.sort_by { |sym| sym.to_s }) + options.values_at(*DEFAULT_OPTIONS.keys.sort!) # fetch or create the instance for this signature @@instances ||= Hash.new From 2d677b30cbc77ffb1e66172be06652c126d786ef Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Thu, 10 Nov 2022 21:16:59 -0300 Subject: [PATCH 2/2] Remove sorting Only required by old Rubies. Co-authored-by: Sutou Kouhei --- lib/csv.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/csv.rb b/lib/csv.rb index 8ef94ce3..45096bb9 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1005,7 +1005,7 @@ class << self def instance(data = $stdout, **options) # create a _signature_ for this method call, data object and options sig = [data.object_id] + - options.values_at(*DEFAULT_OPTIONS.keys.sort!) + options.values_at(*DEFAULT_OPTIONS.keys) # fetch or create the instance for this signature @@instances ||= Hash.new