aboutsummaryrefslogtreecommitdiff
path: root/test/range.go
diff options
context:
space:
mode:
authorMartin Möhrmann <martisch@uos.de>2016-10-27 23:31:38 +0200
committerMartin Möhrmann <martisch@uos.de>2016-10-28 07:58:47 +0000
commitb679665a182bd6ec2989ae759df6b11142921cfb (patch)
tree95a7d3f23fb430c9cdcfe803c4feb648c1253987 /test/range.go
parentf595848e9a1e1d0f64a7018d847167d85f6e83a4 (diff)
downloadgo-b679665a182bd6ec2989ae759df6b11142921cfb.tar.gz
go-b679665a182bd6ec2989ae759df6b11142921cfb.zip
cmd/compile: move stringtoslicebytetmp to the backend
- removes the runtime function stringtoslicebytetmp - removes the generation of calls to stringtoslicebytetmp from the frontend - adds handling of OSTRARRAYBYTETMP in the backend This reduces binary sizes and avoids function call overhead. Change-Id: Ib9988d48549cee663b685b4897a483f94727b940 Reviewed-on: https://go-review.googlesource.com/32158 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Martin Möhrmann <martisch@uos.de> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/range.go')
-rw-r--r--test/range.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/range.go b/test/range.go
index af89edac54..bae7a1c3c9 100644
--- a/test/range.go
+++ b/test/range.go
@@ -110,6 +110,30 @@ func testslice2() {
}
}
+// test that range over []byte(string) only evaluates
+// the expression after "range" once.
+
+func makenumstring() string {
+ nmake++
+ return "\x01\x02\x03\x04\x05"
+}
+
+func testslice3() {
+ s := byte(0)
+ nmake = 0
+ for _, v := range []byte(makenumstring()) {
+ s += v
+ }
+ if nmake != 1 {
+ println("range called makenumstring", nmake, "times")
+ panic("fail")
+ }
+ if s != 15 {
+ println("wrong sum ranging over []byte(makenumstring)", s)
+ panic("fail")
+ }
+}
+
// test that range over array only evaluates
// the expression after "range" once.
@@ -392,6 +416,7 @@ func main() {
testslice()
testslice1()
testslice2()
+ testslice3()
teststring()
teststring1()
teststring2()