summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-22 07:29:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-22 07:29:54 +0000
commit4e5114b0d17aff091267656705c3586ed24b9e1c (patch)
tree6af737dd60b83ecf4869bb5d4afbcfe20d26ec0f
parentc37de3804f735e5c364e033e394042326d677f54 (diff)
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
-rw-r--r--ChangeLog6
-rw-r--r--lib/csv.rb8
2 files changed, 9 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 47b6cb8a67..0c567cbce9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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