mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/csv] Resolve CSV::Converters and HeaderConverters lazy
It's for Ractor. If you want to use the built-in converters, you
should call Ractor.make_shareable(CSV::Converters) and/or
Ractor.make_shareable(CSV::HeaderConverters).
b0b1325d6b
This commit is contained in:
parent
8aaa1c279f
commit
39ecdabe67
Notes:
git
2021-10-24 05:58:05 +09:00
2 changed files with 8 additions and 4 deletions
|
@ -2575,7 +2575,7 @@ class CSV
|
||||||
|
|
||||||
def build_parser_fields_converter
|
def build_parser_fields_converter
|
||||||
specific_options = {
|
specific_options = {
|
||||||
builtin_converters: Converters,
|
builtin_converters_name: :Converters,
|
||||||
}
|
}
|
||||||
options = @base_fields_converter_options.merge(specific_options)
|
options = @base_fields_converter_options.merge(specific_options)
|
||||||
build_fields_converter(@initial_converters, options)
|
build_fields_converter(@initial_converters, options)
|
||||||
|
@ -2587,7 +2587,7 @@ class CSV
|
||||||
|
|
||||||
def build_header_fields_converter
|
def build_header_fields_converter
|
||||||
specific_options = {
|
specific_options = {
|
||||||
builtin_converters: HeaderConverters,
|
builtin_converters_name: :HeaderConverters,
|
||||||
accept_nil: true,
|
accept_nil: true,
|
||||||
}
|
}
|
||||||
options = @base_fields_converter_options.merge(specific_options)
|
options = @base_fields_converter_options.merge(specific_options)
|
||||||
|
|
|
@ -16,7 +16,7 @@ class CSV
|
||||||
@empty_value = options[:empty_value]
|
@empty_value = options[:empty_value]
|
||||||
@empty_value_is_empty_string = (@empty_value == "")
|
@empty_value_is_empty_string = (@empty_value == "")
|
||||||
@accept_nil = options[:accept_nil]
|
@accept_nil = options[:accept_nil]
|
||||||
@builtin_converters = options[:builtin_converters]
|
@builtin_converters_name = options[:builtin_converters_name]
|
||||||
@need_static_convert = need_static_convert?
|
@need_static_convert = need_static_convert?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class CSV
|
||||||
if name.nil? # custom converter
|
if name.nil? # custom converter
|
||||||
@converters << converter
|
@converters << converter
|
||||||
else # named converter
|
else # named converter
|
||||||
combo = @builtin_converters[name]
|
combo = builtin_converters[name]
|
||||||
case combo
|
case combo
|
||||||
when Array # combo converter
|
when Array # combo converter
|
||||||
combo.each do |sub_name|
|
combo.each do |sub_name|
|
||||||
|
@ -80,5 +80,9 @@ class CSV
|
||||||
@need_static_convert or
|
@need_static_convert or
|
||||||
(not @converters.empty?)
|
(not @converters.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def builtin_converters
|
||||||
|
@builtin_converters ||= ::CSV.const_get(@builtin_converters_name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue