From 0c0ee13a1cb6a8156c7a3bf7334efc6ff8c04c5d Mon Sep 17 00:00:00 2001 From: Ryan Warnick Date: Mon, 11 Feb 2013 17:31:25 -0700 Subject: [PATCH] 9253: Before writing a numeric attribute value, ActiveRecord does an implicit conversion of boolean types (true => 1 and false => 0). If the numeric value being assigned is a BigDecimal, then ActiveRecord compares a BigDecimal to true and false. This is known to be very slow in Ruby 1.9.3. --- .../lib/active_record/connection_adapters/column.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 747331f3a11b6..a4b3a0c584fed 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -74,12 +74,13 @@ def binary? def type_cast_for_write(value) return value unless number? - if value == false + case value + when FalseClass 0 - elsif value == true + when TrueClass 1 - elsif value.is_a?(String) && value.blank? - nil + when String + value.presence else value end