1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2016-08-22 07:29:54 +00:00
parent c37de3804f
commit 4e5114b0d1
2 changed files with 9 additions and 5 deletions

View file

@ -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.

View file

@ -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