Skip to content

Commit

Permalink
Setup intermediate attr_writer and attr_reader
Browse files Browse the repository at this point in the history
This ensures that classes loaded in kernel/common such as Binding also
properly track the ivars for attr_* methods. Before Binding didn't get
the proper optimized memory layout, significantly affecting performance
of create a binding.
  • Loading branch information
dbussink committed Feb 10, 2013
1 parent 946837f commit 60db931
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
5 changes: 3 additions & 2 deletions kernel/alpha.rb
Expand Up @@ -523,8 +523,9 @@ def attr_reader_specific(name, method_name)
#
def attr_writer(name)
meth = Rubinius::AccessVariable.set_ivar name
@method_table.store "#{name}=".to_sym, meth, :public
Rubinius::VM.reset_method_cache name
writer_name = "#{name}=".to_sym
@method_table.store writer_name, meth, :public
Rubinius::VM.reset_method_cache writer_name
nil
end

Expand Down
6 changes: 3 additions & 3 deletions kernel/common/load_order18.txt
Expand Up @@ -2,12 +2,12 @@ mirror.rbc
string_mirror.rbc
class.rbc
class18.rbc
binding.rbc
proc.rbc
proc18.rbc
autoload.rbc
module.rbc
module18.rbc
binding.rbc
proc.rbc
proc18.rbc
enumerable.rbc
enumerable18.rbc
enumerator.rbc
Expand Down
6 changes: 3 additions & 3 deletions kernel/common/load_order19.txt
Expand Up @@ -3,12 +3,12 @@ mirror.rbc
string_mirror.rbc
class.rbc
class19.rbc
binding.rbc
proc.rbc
proc19.rbc
autoload.rbc
module.rbc
module19.rbc
binding.rbc
proc.rbc
proc19.rbc
enumerable19.rbc
enumerable.rbc
enumerator.rbc
Expand Down
6 changes: 3 additions & 3 deletions kernel/common/load_order20.txt
Expand Up @@ -3,12 +3,12 @@ mirror.rbc
string_mirror.rbc
class.rbc
class19.rbc
binding.rbc
proc.rbc
proc19.rbc
autoload.rbc
module.rbc
module19.rbc
binding.rbc
proc.rbc
proc19.rbc
enumerable19.rbc
enumerable.rbc
enumerator.rbc
Expand Down
37 changes: 36 additions & 1 deletion kernel/common/module.rb
Expand Up @@ -592,7 +592,9 @@ def add_ivars(code)
end
when Rubinius::AccessVariable
if @seen_ivars
@seen_ivars << code.name
unless @seen_ivars.include?(code.name)
@seen_ivars << code.name
end
else
@seen_ivars = [code.name]
end
Expand Down Expand Up @@ -628,4 +630,37 @@ def freeze
@method_table.freeze
super
end

def attr_reader(name)
meth = Rubinius::AccessVariable.get_ivar name
@method_table.store name, meth, :public
Rubinius::VM.reset_method_cache name
ivar_name = "@#{name}".to_sym
if @seen_ivars
@seen_ivars.each do |ivar|
return nil if ivar == ivar_name
end
@seen_ivars[@seen_ivars.size] = ivar_name
else
@seen_ivars = [ivar_name]
end
nil
end

def attr_writer(name)
meth = Rubinius::AccessVariable.set_ivar name
writer_name = "#{name}=".to_sym
@method_table.store writer_name, meth, :public
Rubinius::VM.reset_method_cache writer_name
ivar_name = "@#{name}".to_sym
if @seen_ivars
@seen_ivars.each do |ivar|
return nil if ivar == ivar_name
end
@seen_ivars[@seen_ivars.size] = ivar_name
else
@seen_ivars = [ivar_name]
end
nil
end
end

0 comments on commit 60db931

Please sign in to comment.