aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-01 18:00:52 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-01 18:00:52 -0700
commit6cd8e3f58ed2d28d07e341793b9e9c00421540a5 (patch)
tree9f8e775d901a73279e7c163826870347e48e9bc6
parentb7aba569c871e09fa8227175626ff09e7e6638de (diff)
downloadrails-6cd8e3f58ed2d28d07e341793b9e9c00421540a5.tar.gz
rails-6cd8e3f58ed2d28d07e341793b9e9c00421540a5.tar.bz2
rails-6cd8e3f58ed2d28d07e341793b9e9c00421540a5.zip
make the identity type a singleton to save on object creation
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb4
-rw-r--r--activerecord/lib/active_record/result.rb6
2 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 07410884a7..fe1480d8c2 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -154,9 +154,7 @@ module ActiveRecord
result = klass.connection.select_all(relation.arel, nil, bind_values)
columns = result.columns.map do |key|
klass.column_types.fetch(key) {
- result.column_types.fetch(key) {
- Class.new { def type_cast(v); v; end }.new
- }
+ result.column_types.fetch(key) { result.identity_type }
}
end
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index 6156b3a5ba..a7a035fe46 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -8,6 +8,8 @@ module ActiveRecord
class Result
include Enumerable
+ IDENTITY_TYPE = Class.new { def type_cast(v); v; end }.new # :nodoc:
+
attr_reader :columns, :rows, :column_types
def initialize(columns, rows, column_types = {})
@@ -17,6 +19,10 @@ module ActiveRecord
@column_types = column_types
end
+ def identity_type # :nodoc:
+ IDENTITY_TYPE
+ end
+
def each
if block_given?
hash_rows.each { |row| yield row }