]> Cypherpunks repositories - gostls13.git/commit
internal/trace/v2: break up ordering.Advance into dispatched methods
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 23 Feb 2024 23:26:49 +0000 (23:26 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 22 Mar 2024 16:14:14 +0000 (16:14 +0000)
commitc2b1463153e0095cf66ca362409d70ff0b6aad26
treeb2c3ac8679de924989d149089255743a9dcafff5
parentc9c88d73f5cb58d0e40cb1b0481c102e6b8b24f1
internal/trace/v2: break up ordering.Advance into dispatched methods

Currently ordering.Advance is one massive switch statement. This isn't
amazing for readability because it's hard to see at a glance what
happens before and after. Some of the state sharing is nice, but
otherwise, it can get confusing quickly (especially where break is used,
and where there are nested switches).

This CL breaks up the switch statement into individual methods on
ordering.Advance which are loaded and dispatched from a table. This CL
uses a table instead of a switch statement because the arguments passed
are all the same each time, and the table can provide a very precise
mapping for each event; with a switch, we'd be tempted to group cases
that call the same handler method together. It also prevents us from
using defer in many cases, which may help clean up the code. (Each case
in the switch is completely self-contained, yet we can't use a defer
because it's function-scoped.)

As an aside, this should also improve performance a bit. The Go compiler
doesn't handle massive irregular functions very well, especially one
with a lot of return points and (previously) a conditionally deferred
call.

Change-Id: I3ef2cf75301c795b6f23da1e058b0ac303fea8bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/566576
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/internal/trace/v2/order.go