]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/trace: replace loop with append(slice, slice2...)
authorcuiweixie <cuiweixie@gmail.com>
Thu, 29 Sep 2022 13:03:15 +0000 (21:03 +0800)
committerMichael Pratt <mpratt@google.com>
Mon, 3 Oct 2022 15:30:36 +0000 (15:30 +0000)
Change-Id: I4686f36a8f718fea1a08d816bc14e24e3528bb07
Reviewed-on: https://go-review.googlesource.com/c/go/+/436706
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/cmd/trace/annotations.go
src/cmd/trace/trace.go

index a276d7b642815d987d6598b09079d57827cedebd..be515880e61277180ae208c513f503e422010d62 100644 (file)
@@ -446,9 +446,7 @@ func (task *taskDesc) descendants() []*taskDesc {
        res := []*taskDesc{task}
        for i := 0; len(res[i:]) > 0; i++ {
                t := res[i]
-               for _, c := range t.children {
-                       res = append(res, c)
-               }
+               res = append(res, t.children...)
        }
        return res
 }
index e6c4cca72e00601193727c7d686f18f2ff8467e0..253b5dafe5aea2bdf938f3d750939c1ff2830dd8 100644 (file)
@@ -765,10 +765,8 @@ func generateTrace(params *traceParams, consumer traceConsumer) error {
        // Display task and its regions if we are in task-oriented presentation mode.
        if ctx.mode&modeTaskOriented != 0 {
                // sort tasks based on the task start time.
-               sortedTask := make([]*taskDesc, 0, len(ctx.tasks))
-               for _, task := range ctx.tasks {
-                       sortedTask = append(sortedTask, task)
-               }
+               sortedTask := make([]*taskDesc, len(ctx.tasks))
+               copy(sortedTask, ctx.tasks)
                sort.SliceStable(sortedTask, func(i, j int) bool {
                        ti, tj := sortedTask[i], sortedTask[j]
                        if ti.firstTimestamp() == tj.firstTimestamp() {