]> Cypherpunks repositories - gostls13.git/commitdiff
test/bench/go1: fix gzip test
authorShenghou Ma <minux.ma@gmail.com>
Mon, 4 Jun 2012 16:14:39 +0000 (00:14 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Mon, 4 Jun 2012 16:14:39 +0000 (00:14 +0800)
      We can't depend on init() order, and certainly we don't want to
register all future benchmarks that use jsonbytes or jsondata to init()
in json_test.go, so we use a more general solution: make generation of
jsonbytes and jsondata their own function so that the compiler will take
care of the order.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6282046

test/bench/go1/gob_test.go
test/bench/go1/json_test.go

index 00eeed57a569197eb0ffa38ca8d06547d2bfc5ff..b172b805ad284efa25b96e643742798420e1193a 100644 (file)
@@ -21,9 +21,7 @@ var (
        gobdata  *JSONResponse
 )
 
-func gobinit() {
-       // gobinit is called after json's init,
-       // because it uses jsondata.
+func init() {
        gobdata = gobResponse(&jsondata)
 
        var buf bytes.Buffer
index 5a3012167b1f9c827b091f09bfba9099929fe8e1..614e24a810cff229797ad7d45cde290d0b182008 100644 (file)
@@ -17,11 +17,11 @@ import (
 )
 
 var (
-       jsonbytes []byte
-       jsondata  JSONResponse
+       jsonbytes = makeJsonBytes()
+       jsondata  = makeJsonData()
 )
 
-func init() {
+func makeJsonBytes() []byte {
        var r io.Reader
        r = strings.NewReader(jsonbz2_base64)
        r = base64.NewDecoder(base64.StdEncoding, r)
@@ -30,12 +30,15 @@ func init() {
        if err != nil {
                panic(err)
        }
-       jsonbytes = b
+       return b
+}
 
-       if err := json.Unmarshal(jsonbytes, &jsondata); err != nil {
+func makeJsonData() JSONResponse {
+       var v JSONResponse
+       if err := json.Unmarshal(jsonbytes, &v); err != nil {
                panic(err)
        }
-       gobinit()
+       return v
 }
 
 type JSONResponse struct {