diff --git a/benchmark/convert_nil.yaml b/benchmark/convert_nil.yaml index f32c6f10..76613806 100644 --- a/benchmark/convert_nil.yaml +++ b/benchmark/convert_nil.yaml @@ -4,6 +4,8 @@ contexts: csv: 3.0.1 - gems: csv: 3.0.2 + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/parse.yaml b/benchmark/parse.yaml index 25ccaf24..4289995f 100644 --- a/benchmark/parse.yaml +++ b/benchmark/parse.yaml @@ -4,6 +4,8 @@ contexts: csv: 3.0.1 - gems: csv: 3.0.2 + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/parse_liberal_parsing.yaml b/benchmark/parse_liberal_parsing.yaml index dcbf5985..41307e11 100644 --- a/benchmark/parse_liberal_parsing.yaml +++ b/benchmark/parse_liberal_parsing.yaml @@ -2,6 +2,8 @@ loop_count: 100 contexts: - gems: csv: 3.0.2 + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/parse_quote_char_nil.yaml b/benchmark/parse_quote_char_nil.yaml index f92fd33b..f9cb8283 100644 --- a/benchmark/parse_quote_char_nil.yaml +++ b/benchmark/parse_quote_char_nil.yaml @@ -1,5 +1,7 @@ loop_count: 100 contexts: + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/parse_strip.yaml b/benchmark/parse_strip.yaml index a0230fd1..fe9dbeaa 100644 --- a/benchmark/parse_strip.yaml +++ b/benchmark/parse_strip.yaml @@ -1,5 +1,7 @@ loop_count: 100 contexts: + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/read.yaml b/benchmark/read.yaml index b06dbe16..15fc26f5 100644 --- a/benchmark/read.yaml +++ b/benchmark/read.yaml @@ -4,6 +4,8 @@ contexts: csv: 3.0.1 - gems: csv: 3.0.2 + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/shift.yaml b/benchmark/shift.yaml index eb6fd80e..8011a4fa 100644 --- a/benchmark/shift.yaml +++ b/benchmark/shift.yaml @@ -4,6 +4,8 @@ contexts: csv: 3.0.1 - gems: csv: 3.0.2 + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/benchmark/write.yaml b/benchmark/write.yaml index 5b7d1943..019927c2 100644 --- a/benchmark/write.yaml +++ b/benchmark/write.yaml @@ -4,6 +4,8 @@ contexts: csv: 3.0.1 - gems: csv: 3.0.2 + - gems: + csv: 3.3.0 - name: "master" prelude: | $LOAD_PATH.unshift(File.expand_path("lib")) diff --git a/lib/csv.rb b/lib/csv.rb index 0cf49eb2..87278593 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -959,6 +959,12 @@ def initialize(encoding, line_number) write_empty_value: "", }.freeze + module NoQuotedFields # :nodoc: + def self.[](_index) + false + end + end + class << self # :call-seq: # instance(string, **options) diff --git a/lib/csv/fields_converter.rb b/lib/csv/fields_converter.rb index d15977d3..950a3b6b 100644 --- a/lib/csv/fields_converter.rb +++ b/lib/csv/fields_converter.rb @@ -44,7 +44,7 @@ def empty? @converters.empty? end - def convert(fields, headers, lineno, quoted_fields) + def convert(fields, headers, lineno, quoted_fields = NoQuotedFields) return fields unless need_convert? fields.collect.with_index do |field, index| diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index d7fcd10e..917ec36a 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -767,7 +767,7 @@ def prepare_header case headers when Array @raw_headers = headers - quoted_fields = [false] * @raw_headers.size + quoted_fields = NoQuotedFields @use_headers = true when String @raw_headers, quoted_fields = parse_headers(headers) @@ -944,11 +944,9 @@ def parse_no_quote(&block) if line.empty? next if @skip_blanks row = [] - quoted_fields = [] else line = strip_value(line) row = line.split(@split_column_separator, -1) - quoted_fields = [false] * row.size if @max_field_size row.each do |column| validate_field_size(column) @@ -962,7 +960,7 @@ def parse_no_quote(&block) end end @last_line = original_line - emit_row(row, quoted_fields, &block) + emit_row(row, &block) end end @@ -984,7 +982,7 @@ def parse_quotable_loose(&block) next end row = [] - quoted_fields = [] + quoted_fields = NoQuotedFields elsif line.include?(@cr) or line.include?(@lf) @scanner.keep_back @need_robust_parsing = true @@ -1046,13 +1044,13 @@ def parse_quotable_robust(&block) quoted_fields << @quoted_column_value elsif parse_row_end if row.empty? and value.nil? - emit_row([], [], &block) unless @skip_blanks + emit_row(row, &block) unless @skip_blanks else row << value quoted_fields << @quoted_column_value emit_row(row, quoted_fields, &block) row = [] - quoted_fields = [] + quoted_fields.clear end skip_needless_lines start_row @@ -1257,7 +1255,7 @@ def start_row @scanner.keep_start end - def emit_row(row, quoted_fields, &block) + def emit_row(row, quoted_fields = NoQuotedFields, &block) @lineno += 1 raw_row = row diff --git a/lib/csv/writer.rb b/lib/csv/writer.rb index 030a295b..b59f111e 100644 --- a/lib/csv/writer.rb +++ b/lib/csv/writer.rb @@ -40,8 +40,7 @@ def <<(row) @lineno += 1 if @fields_converter - quoted_fields = [false] * row.size - row = @fields_converter.convert(row, nil, lineno, quoted_fields) + row = @fields_converter.convert(row, nil, lineno) end i = -1