Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan McAulay committed Mar 15, 2017
1 parent 744104f commit ce68bf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 8 additions & 6 deletions dig/dig.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ func (g *Graph) Register(c interface{}) error {
}
return g.registerConstructor(c)
case reflect.Ptr:
if ctype.Elem().Kind() == reflect.Interface {
ctype = ctype.Elem()
}
return g.registerObject(c, ctype)
default:
return errParamType
Expand Down Expand Up @@ -200,11 +197,16 @@ func (g *Graph) String() string {
}

func (g *Graph) registerObject(o interface{}, otype reflect.Type) error {
v := reflect.ValueOf(o)
if otype.Elem().Kind() == reflect.Interface {
otype = otype.Elem()
v = v.Elem()
}
n := objNode{
obj: o,
node: node{
objType: otype,
cached: true,
objType: otype,
cached: true,
cachedValue: v,
},
}

Expand Down
8 changes: 1 addition & 7 deletions dig/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,11 @@ func (n node) id() string {

type objNode struct {
node

obj interface{}
}

// Return the earlier provided instance
func (n *objNode) value(g *Graph) (reflect.Value, error) {
v := reflect.ValueOf(n.obj)
if n.objType.Kind() == reflect.Interface {
v = v.Elem()
}
return v, nil
return n.cachedValue, nil
}

func (n objNode) dependencies() []interface{} {
Expand Down

0 comments on commit ce68bf6

Please sign in to comment.