ruby-changes:43912
From: nobu <ko1@a...>
Date: Mon, 22 Aug 2016 16:30:00 +0900 (JST)
Subject: [ruby-changes:43912] nobu:r55985 (trunk): csv.rb: performance with very long quoted lines
nobu 2016-08-22 16:29:54 +0900 (Mon, 22 Aug 2016) New Revision: 55985 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55985 Log: csv.rb: performance with very long quoted lines * 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] Modified files: trunk/ChangeLog trunk/lib/csv.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 55984) +++ ChangeLog (revision 55985) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Aug 22 16:29:52 2016 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * man/irb.1: remove useless -width option. Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 55984) +++ lib/csv.rb (revision 55985) @@ -1856,7 +1856,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1856 # 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 https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1864 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/