]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: correct comment for len check when make slice
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 11 Apr 2020 14:49:10 +0000 (21:49 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 11 Apr 2020 16:20:57 +0000 (16:20 +0000)
CL 226737 optimizes len check when make slice. The comment that cap is
constrainted to [0, 2^31) is not quite true, it's 31 or 63 depends on
whether it's 32/64-bit systems.

Change-Id: I6f54e41827ffe4d0b67a44975da3ce07b2fabbad
Reviewed-on: https://go-review.googlesource.com/c/go/+/227803
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/walk.go

index 57d71bf3d451f31d4cdd93e88e923765bfe1136b..9eab170ddbab89486605f2270a259770a60f7ec6 100644 (file)
@@ -1352,7 +1352,8 @@ opswitch:
                                Fatalf("walkexpr: invalid index %v", r)
                        }
 
-                       // cap is constrained to [0,2^31), so it's safe to do:
+                       // cap is constrained to [0,2^31) or [0,2^63) depending on whether
+                       // we're in 32-bit or 64-bit systems. So it's safe to do:
                        //
                        // if uint64(len) > cap {
                        //     if len < 0 { panicmakeslicelen() }