Skip to content

Commit

Permalink
Refactor to remove nested instance variable struct in object/class
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jul 24, 2024
1 parent cda59b7 commit 92cbe74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
8 changes: 4 additions & 4 deletions class.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type class struct {
Object
super RClass
mt
iv
iv ivTable
}

type Class struct {
Expand Down Expand Up @@ -191,18 +191,18 @@ func (mrb *State) defineMethodRaw(class RClass, name Symbol, method Method) {

func (c *class) ivPut(sym Symbol, val Value) {
if c.iv == nil {
c.iv = make(iv)
c.iv = make(ivTable)
}

c.iv.Put(sym, val)
c.iv[sym] = val
}

func (c *class) ivGet(sym Symbol) Value {
if c.iv == nil {
return nil
}

return c.iv.Get(sym)
return c.iv[sym]
}

func (c *class) mtPut(sym Symbol, method Method) {
Expand Down
8 changes: 4 additions & 4 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ RObject = &Object{}
type Object struct {
class RClass
flags uint32
iv
iv ivTable
}

func (obj *Object) Class() RClass {
Expand All @@ -32,18 +32,18 @@ func (obj *Object) Flags() uint32 {

func (obj *Object) ivPut(sym Symbol, val Value) {
if obj.iv == nil {
obj.iv = make(iv)
obj.iv = make(ivTable)
}

obj.iv.Put(sym, val)
obj.iv[sym] = val
}

func (obj *Object) ivGet(sym Symbol) Value {
if obj.iv == nil {
return nil
}

return obj.iv.Get(sym)
return obj.iv[sym]
}

func (mrb *State) includeModuleAt(class, insPos, module RClass, superSearch int) int {
Expand Down
9 changes: 0 additions & 9 deletions variable.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package mruby

type ivTable map[Symbol]Value
type iv = ivTable

func (iv ivTable) Get(sym Symbol) Value {
return iv[sym]
}

func (iv ivTable) Put(sym Symbol, val Value) {
iv[sym] = val
}

func (mrb *State) ObjectInstanceVariableSetForce(obj RObject, name Symbol, val Value) {
obj.ivPut(name, val)
Expand Down

0 comments on commit 92cbe74

Please sign in to comment.