aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-05-17 10:50:36 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-05-18 11:34:42 +0200
commit17b3eb97de1822644d1611efbfc9c7cd2dd7722c (patch)
treef2fe846f50d8f8da3ad968e33c1cc7286df9b4f7
parent9d7b583eae5f9d459920d207848863917fc58416 (diff)
prog: speed up foreachArgImpl
Don't generate garbage for ctx. This speeds up mutation tests by 20%.
-rw-r--r--prog/analysis.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/prog/analysis.go b/prog/analysis.go
index 9300240b5..c41dae25b 100644
--- a/prog/analysis.go
+++ b/prog/analysis.go
@@ -108,11 +108,11 @@ type ArgCtx struct {
}
func ForeachSubArg(arg Arg, f func(Arg, *ArgCtx)) {
- foreachArgImpl(arg, ArgCtx{}, f)
+ foreachArgImpl(arg, &ArgCtx{}, f)
}
func ForeachArg(c *Call, f func(Arg, *ArgCtx)) {
- ctx := ArgCtx{}
+ ctx := &ArgCtx{}
if c.Ret != nil {
foreachArgImpl(c.Ret, ctx, f)
}
@@ -123,8 +123,10 @@ func ForeachArg(c *Call, f func(Arg, *ArgCtx)) {
}
}
-func foreachArgImpl(arg Arg, ctx ArgCtx, f func(Arg, *ArgCtx)) {
- f(arg, &ctx)
+func foreachArgImpl(arg Arg, ctx *ArgCtx, f func(Arg, *ArgCtx)) {
+ ctx0 := *ctx
+ defer func() { *ctx = ctx0 }()
+ f(arg, ctx)
if ctx.Stop {
return
}