Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bfce7bceb1d5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6a875ceef70a
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 25, 2015

  1. Use methods instead of procs for converters.

    This is a temporary fix to improve perf of converters since JRuby
    does not currently JIT blocks.
    
    See #3348.
    headius committed Sep 25, 2015
    Copy the full SHA
    9de48c2 View commit details
  2. Copy the full SHA
    6a875ce View commit details
Showing with 38 additions and 29 deletions.
  1. +38 −26 lib/ruby/stdlib/csv.rb
  2. +0 −3 test/mri/excludes/TestCSV/Encodings.rb
  3. 0 test/mri/excludes/TestCSV/{ → Encodings}/DifferentOFS.rb
64 changes: 38 additions & 26 deletions lib/ruby/stdlib/csv.rb
Original file line number Diff line number Diff line change
@@ -944,29 +944,35 @@ class MalformedCSVError < RuntimeError; end
# To add a combo field, the value should be an Array of names. Combo fields
# can be nested with other combo fields.
#
Converters = { integer: lambda { |f|
Integer(f.encode(ConverterEncoding)) rescue f
},
float: lambda { |f|
Float(f.encode(ConverterEncoding)) rescue f
},
converter_methods = Module.new do
def self.integer(f)
Integer(f.encode(ConverterEncoding)) rescue f
end
def self.float(f)
Float(f.encode(ConverterEncoding)) rescue f
end
def self.date(f)
begin
e = f.encode(ConverterEncoding)
e =~ DateMatcher ? Date.parse(e) : f
rescue # encoding conversion or date parse errors
f
end
end
def self.date_time(f)
begin
e = f.encode(ConverterEncoding)
e =~ DateTimeMatcher ? DateTime.parse(e) : f
rescue # encoding conversion or date parse errors
f
end
end
end
Converters = { integer: converter_methods.method(:integer),
float: converter_methods.method(:float),
numeric: [:integer, :float],
date: lambda { |f|
begin
e = f.encode(ConverterEncoding)
e =~ DateMatcher ? Date.parse(e) : f
rescue # encoding conversion or date parse errors
f
end
},
date_time: lambda { |f|
begin
e = f.encode(ConverterEncoding)
e =~ DateTimeMatcher ? DateTime.parse(e) : f
rescue # encoding conversion or date parse errors
f
end
},
date: converter_methods.method(:date),
date_time: converter_methods.method(:date_time),
all: [:date_time, :numeric] }

#
@@ -989,12 +995,18 @@ class MalformedCSVError < RuntimeError; end
# To add a combo field, the value should be an Array of names. Combo fields
# can be nested with other combo fields.
#
HeaderConverters = {
downcase: lambda { |h| h.encode(ConverterEncoding).downcase },
symbol: lambda { |h|
header_converters = Module.new do
def self.downcase(h)
h.encode(ConverterEncoding).downcase
end
def self.symbol(h)
h.encode(ConverterEncoding).downcase.strip.gsub(/\s+/, "_").
gsub(/\W+/, "").to_sym
}
end
end
HeaderConverters = {
downcase: header_converters.method(:downcase),
symbol: header_converters.method(:symbol)
}

#
3 changes: 0 additions & 3 deletions test/mri/excludes/TestCSV/Encodings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
exclude :test_auto_line_ending_detection, "needs investigation"
exclude :test_can_write_csv_in_any_encoding, "needs investigation"
exclude :test_read_with_default_encoding, "needs investigation"
exclude :test_reading_with_most_encodings, "needs investigation"
exclude :test_regular_expression_escaping, "needs investigation"
File renamed without changes.