diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-22 07:29:54 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-22 07:29:54 +0000 |
commit | 6fdda02efae859b6ddef9568315f34e65fdec789 (patch) | |
tree | 6af737dd60b83ecf4869bb5d4afbcfe20d26ec0f /lib/csv.rb | |
parent | 5073a51fa6610f011ef58c57f0bcc5d1e37b023a (diff) | |
download | ruby-6fdda02efae859b6ddef9568315f34e65fdec789.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/csv.rb')
-rw-r--r-- | lib/csv.rb | 8 |
1 files changed, 3 insertions, 5 deletions
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 |