Skip to content

Commit

Permalink
csv.rb: performance with very long quoted lines
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Aug 22, 2016
1 parent c37de38 commit 4e5114b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 3 additions & 5 deletions lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1856,23 +1856,21 @@ def shift
# 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}"
end
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
Expand Down

0 comments on commit 4e5114b

Please sign in to comment.