From 0efc8b21881ab35fdb45547088b1935fc8ebf263 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 20 Feb 2017 22:37:07 -0500 Subject: runtime: avoid repeated findmoduledatap calls Currently almost every function that deals with a *_func has to first look up the *moduledata for the module containing the function's entry point. This means we almost always do at least two identical module lookups whenever we deal with a *_func (one to get the *_func and another to get something from its module data) and sometimes several more. Fix this by making findfunc return a new funcInfo type that embeds *_func, but also includes the *moduledata, and making all of the functions that currently take a *_func instead take a funcInfo and use the already-found *moduledata. This transformation is trivial for the most part, since the *_func type is usually inferred. The annoying part is that we can no longer use nil to indicate failure, so this introduces a funcInfo.valid() method and replaces nil checks with calls to valid. Change-Id: I9b8075ef1c31185c1943596d96dec45c7ab5100f Reviewed-on: https://go-review.googlesource.com/37331 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Michael Hudson-Doyle --- src/runtime/plugin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/runtime/plugin.go') diff --git a/src/runtime/plugin.go b/src/runtime/plugin.go index ea246509cc..682caacb21 100644 --- a/src/runtime/plugin.go +++ b/src/runtime/plugin.go @@ -95,7 +95,7 @@ func pluginftabverify(md *moduledata) { continue } - f := (*_func)(unsafe.Pointer(&md.pclntable[md.ftab[i].funcoff])) + f := funcInfo{(*_func)(unsafe.Pointer(&md.pclntable[md.ftab[i].funcoff])), md} name := funcname(f) // A common bug is f.entry has a relocation to a duplicate @@ -104,7 +104,7 @@ func pluginftabverify(md *moduledata) { name2 := "none" entry2 := uintptr(0) f2 := findfunc(entry) - if f2 != nil { + if f2.valid() { name2 = funcname(f2) entry2 = f2.entry } -- cgit v1.3