Hi,
I want to know if there are any plan/updates to inline functions that [might] call another function inside? It has both code readability benefits and performance benefit? I know this question has been asked before, just want to check if there are any updates? Thanks!
Example of improving readability:
Original:
type Visitor struct {
OnVertex func (v VertexID) error
OnEdge func (e EdgeID) error
}
func Walk(g Graph, visitor Visitor) error {
...
if visitor.OnVertex != nil {
if err := v.OnVertex(v); err != nil {
return err
}
}
}
If we can do it like this without losing any performance, it will be great!
type Visitor struct {
OnVertex func (v VertexID) error
OnEdge func (e EdgeID) error
}
func (v Visitor) CallOnVertex(v VertexID) error {
if v.OnVertex != nil {
return v.OnVertex(v)
}
return nil
}
func (v Visitor) CallOnEdge(e EdgeID) error {
if v.OnEdge != nil {
return v.OnEdge(e)
}
return nil
}
func Walk(g Graph, visitor Visitor) error {
...
if err := v.OnVertex(v); err != nil {
return err
}
}
Example of improving performance;
func (c *Cache) Lookup(e Item) Value {
v, ok := c.cacheMap[e];
if !ok { // This happens very rare.
v = c.interalHeavyLookup(e)
c.cacheMap[e] = v
return v
}
return v
}
Otherwise we have to manually inline this function everywhere for performance :(