From 6cd8e3f58ed2d28d07e341793b9e9c00421540a5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 1 Jul 2013 18:00:52 -0700 Subject: make the identity type a singleton to save on object creation --- activerecord/lib/active_record/relation/calculations.rb | 4 +--- activerecord/lib/active_record/result.rb | 6 ++++++ 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 } -- cgit v1.2.3