Project

General

Profile

Feature #4017 ยป ruby_19_csv_parser_speedup.patch

Patch 2/2 - ender672 (Timothy Elliott), 11/03/2010 09:43 AM

View differences:

lib/csv.rb (working copy)
1904 1904
          return line
1905 1905
        when @col_sep
1906 1906
          return line << nil
1907
        when @col_sep_quote
1908
          buf = @quote_char
1909
          next
1907 1910
        end
1908 1911

  
1909 1912
        break unless buf.slice!(0, @col_sep.size) == @col_sep
......
1968 1971
      return unless @data_buf = @io.gets(@quote_char, @io_read_limit)
1969 1972
    end
1970 1973

  
1971
    loop do
1972
      if newline = @data_buf.index(@row_sep)
1973
        break if newline == @data_buf.size - @row_sep.size
1974
        return @data_buf.slice!(0, newline + @row_sep.size)
1975
      end
1974
    case @data_buf
1975
    when @col_sep_quote, @quote_char
1976
    else
1977
      loop do
1978
        if newline = @data_buf.index(@row_sep)
1979
          break if newline == @data_buf.size - @row_sep.size
1980
          return @data_buf.slice!(0, newline + @row_sep.size)
1981
        end
1976 1982

  
1977
      break if @io.eof? || @data_buf.end_with?(@quote_char)
1983
        break if @io.eof? || @data_buf.end_with?(@quote_char)
1978 1984

  
1979
      if @field_size_limit && @data_buf.size > @field_size_limit
1980
        raise MalformedCSVError, "Field size exceeded on line #{@lineno}."
1981
      end
1985
        if @field_size_limit && @data_buf.size > @field_size_limit
1986
          raise MalformedCSVError, "Field size exceeded on line #{@lineno}."
1987
        end
1982 1988

  
1983
      @data_buf += @io.gets(@quote_char, @io_read_limit) unless align_data_buf
1989
        @data_buf += @io.gets(@quote_char, @io_read_limit) unless align_data_buf
1990
      end
1984 1991
    end
1985 1992

  
1986 1993
    return_buf = @data_buf
......
2104 2111
    @field_size_limit = options.delete(:field_size_limit)
2105 2112
    @io_read_limit    = options.delete(:io_read_limit)
2106 2113
    @nl_lf            = encode_str("\r\n")
2114
    @col_sep_quote    = @col_sep + @quote_char
2107 2115
  end
2108 2116

  
2109 2117
  #