Skip to content

Commit ad81c30

Browse files
committed
More efficiently reset inspect implementation
Not that `inspect` is anywhere close to be a hostspot, but just to not allow a less defficient pattern. Instead of allocating an UnboundMethod and bind_call it, we can directly replace the method.
1 parent 3295823 commit ad81c30

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

activerecord/lib/active_record/normalization.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ def hash
152152
[self.class, cast_type, normalizer, normalize_nil?].hash
153153
end
154154

155-
def inspect
156-
Kernel.instance_method(:inspect).bind_call(self)
157-
end
155+
define_method(:inspect, Kernel.instance_method(:inspect))
158156

159157
private
160158
def normalize(value)

activerecord/lib/active_record/type/serialized.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def serialize(value)
3030
end
3131
end
3232

33-
def inspect
34-
Kernel.instance_method(:inspect).bind_call(self)
35-
end
33+
define_method(:inspect, Kernel.instance_method(:inspect))
3634

3735
def changed_in_place?(raw_old_value, value)
3836
return false if value.nil?

0 commit comments

Comments
 (0)