diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/csv.rb | 8 |
2 files changed, 9 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Mon Aug 22 16:29:52 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/csv.rb (CSV#shift): store partial quoted strings in an array + and join at last, to improve performance with very long quoted + lines. [ruby-core:76987] [Bug #12691] + Mon Aug 22 14:35:57 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * man/irb.1: remove useless -width option. diff --git a/lib/csv.rb b/lib/csv.rb index 509e9780fa..b68bcb0fc5 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1856,7 +1856,7 @@ class CSV # If we are continuing a previous column if part[-1] == @quote_char && part.count(@quote_char) % 2 != 0 # extended column ends - csv.last << part[0..-2] + csv[-1] = csv[-1].push(part[0..-2]).join("") if csv.last =~ @parsers[:stray_quote] raise MalformedCSVError, "Missing or stray quote in line #{lineno + 1}" @@ -1864,15 +1864,13 @@ class CSV csv.last.gsub!(@quote_char * 2, @quote_char) in_extended_col = false else - csv.last << part - csv.last << @col_sep + csv.last.push(part, @col_sep) end elsif part[0] == @quote_char # If we are starting a new quoted column if part.count(@quote_char) % 2 != 0 # start an extended column - csv << part[1..-1] - csv.last << @col_sep + csv << [part[1..-1], @col_sep] in_extended_col = true elsif part[-1] == @quote_char # regular quoted column |