cache index resolution
resolve once and reuse also use non checking version of get/set as index per definition must be ok This creates some speedup, but mostly avoids some weird hang in Thread::Queue.pop for many seconds
This commit is contained in:
parent
84de400529
commit
66e0d4ae26
@ -18,17 +18,23 @@ module Risc
|
|||||||
end
|
end
|
||||||
def set(index , value)
|
def set(index , value)
|
||||||
range_check(index)
|
range_check(index)
|
||||||
|
_set(index,value)
|
||||||
|
end
|
||||||
|
alias :[]= :set
|
||||||
|
def _set(index , value)
|
||||||
@memory[index] = value
|
@memory[index] = value
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
alias :[]= :set
|
|
||||||
|
|
||||||
def get(index)
|
def get(index)
|
||||||
range_check(index)
|
range_check(index)
|
||||||
@memory[index]
|
_get(index)
|
||||||
end
|
end
|
||||||
alias :[] :get
|
alias :[] :get
|
||||||
|
|
||||||
|
def _get(index)
|
||||||
|
@memory[index]
|
||||||
|
end
|
||||||
|
|
||||||
def size
|
def size
|
||||||
@memory.length
|
@memory.length
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
require_relative "fake_memory"
|
require_relative "fake_memory"
|
||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
def self.variable_index(clazz_name , name)
|
|
||||||
clazz = clazz_name.split("::").last.to_sym
|
|
||||||
type = self.type_names[clazz]
|
|
||||||
i = type.keys.index(name)
|
|
||||||
raise "no #{name} for #{clazz}" unless i
|
|
||||||
i + 1
|
|
||||||
end
|
|
||||||
class Object
|
class Object
|
||||||
|
|
||||||
def self.allocate
|
def self.allocate
|
||||||
@ -35,26 +28,30 @@ module Parfait
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.variable_index( name)
|
||||||
|
if(name == :type)
|
||||||
|
return Parfait::TYPE_INDEX
|
||||||
|
end
|
||||||
|
clazz = self.name.split("::").last.to_sym
|
||||||
|
type = Parfait.type_names[clazz]
|
||||||
|
i = type.keys.index(name)
|
||||||
|
raise "no #{name} for #{clazz}:#{type.keys}" unless i
|
||||||
|
i + 1
|
||||||
|
end
|
||||||
|
|
||||||
def self.define_getter(name)
|
def self.define_getter(name)
|
||||||
|
index = variable_index(name)
|
||||||
define_method(name) do
|
define_method(name) do
|
||||||
#puts "GETTING #{name} for #{self.class.name} in #{object_id.to_s(16)}"
|
#puts "GETTING #{name} for #{self.class.name} in #{object_id.to_s(16)}"
|
||||||
if(name == :type)
|
@memory._get(index)
|
||||||
return @memory[0]
|
|
||||||
end
|
|
||||||
index = Parfait.variable_index(self.class.name, name)
|
|
||||||
get_internal_word(index)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.define_setter(name)
|
def self.define_setter(name)
|
||||||
|
index = variable_index(name)
|
||||||
define_method("#{name}=".to_sym ) do |value|
|
define_method("#{name}=".to_sym ) do |value|
|
||||||
#puts "SETTING #{name}= for #{self.class.name} in #{object_id.to_s(16)}"
|
#puts "SETTING #{name}= for #{self.class.name} in #{object_id.to_s(16)}"
|
||||||
if(name == :type)
|
@memory._set(index , value)
|
||||||
@memory[0] = value
|
|
||||||
return value
|
|
||||||
end
|
|
||||||
index = Parfait.variable_index(self.class.name, name)
|
|
||||||
set_internal_word(index , value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user