Skip to content

Commit 1d6a15b

Browse files
committed
Optimize Data by creating a copy of each method for each subclass
1 parent e9e3973 commit 1d6a15b

File tree

1 file changed

+5
-2
lines changed
  • src/main/ruby/truffleruby/core

1 file changed

+5
-2
lines changed

src/main/ruby/truffleruby/core/data.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ def self.new(*args, **kwargs)
8383
# to redefine #initialize in the returned Data subclass and use super() to use the #initialize just below.
8484
# CRuby defines these directly on Data, but that is suboptimal for performance.
8585
# We want to have a specialized copy of these methods for each Data subclass.
86-
instance_methods_module = Module.new do
86+
instance_methods_module = Module.new
87+
instance_methods_module.module_eval "#{<<~'RUBY'}"
88+
# truffleruby_primitives: true
89+
8790
def initialize(**kwargs)
8891
members_hash = Primitive.class(self)::CLASS_MEMBERS_HASH
8992
kwargs.each do |member, value|
@@ -219,7 +222,7 @@ def hash
219222
220223
Primitive.vm_hash_end(val)
221224
end
222-
end
225+
RUBY
223226

224227
klass.include instance_methods_module
225228

0 commit comments

Comments
 (0)