From 88876f02c1050be989500090763203a36c70597b Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 8 Sep 2022 06:19:05 +0900 Subject: [PATCH] [ruby/csv] All Enumerable based methods consume the same lines with other methods This may have a performance penalty. We should benchmark this. GitHub: fix https://github.com/ruby/csv/pull/260 Reported by Lhoussaine Ghallou. Thanks!!! https://github.com/ruby/csv/commit/acc05116c5 --- lib/csv.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/csv.rb b/lib/csv.rb index 78c3029e7b..d4dc569b83 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -2592,14 +2592,7 @@ class CSV # # Raises IOError (not opened for reading) # csv.read def read - rows = [] - enumerator = parser_enumerator - begin - while true - rows << enumerator.next - end - rescue StopIteration - end + rows = to_a if parser.use_headers? Table.new(rows, headers: parser.headers) else