Procházet zdrojové kódy

http2: reduce alloc-heavy init

Moves test cases into the test where they're used, to remove
distractions when profiling unrelated tests.

Also this is my style preference, to remove globals and reduce the
scope of variables.

Change-Id: Ie9cd41b16aad9acf5e210f1fb6f19a7fce52180d
Reviewed-on: https://go-review.googlesource.com/20996
Reviewed-by: Andrew Gerrand <adg@golang.org>
Brad Fitzpatrick před 10 roky
rodič
revize
4d06dbdaa6
1 změnil soubory, kde provedl 21 přidání a 21 odebrání
  1. 21 21
      http2/transport_test.go

+ 21 - 21
http2/transport_test.go

@@ -326,28 +326,28 @@ func randString(n int) string {
 	return string(b)
 	return string(b)
 }
 }
 
 
-var bodyTests = []struct {
-	body         string
-	noContentLen bool
-}{
-	{body: "some message"},
-	{body: "some message", noContentLen: true},
-	{body: ""},
-	{body: "", noContentLen: true},
-	{body: strings.Repeat("a", 1<<20), noContentLen: true},
-	{body: strings.Repeat("a", 1<<20)},
-	{body: randString(16<<10 - 1)},
-	{body: randString(16 << 10)},
-	{body: randString(16<<10 + 1)},
-	{body: randString(512<<10 - 1)},
-	{body: randString(512 << 10)},
-	{body: randString(512<<10 + 1)},
-	{body: randString(1<<20 - 1)},
-	{body: randString(1 << 20)},
-	{body: randString(1<<20 + 2)},
-}
-
 func TestTransportBody(t *testing.T) {
 func TestTransportBody(t *testing.T) {
+	bodyTests := []struct {
+		body         string
+		noContentLen bool
+	}{
+		{body: "some message"},
+		{body: "some message", noContentLen: true},
+		{body: ""},
+		{body: "", noContentLen: true},
+		{body: strings.Repeat("a", 1<<20), noContentLen: true},
+		{body: strings.Repeat("a", 1<<20)},
+		{body: randString(16<<10 - 1)},
+		{body: randString(16 << 10)},
+		{body: randString(16<<10 + 1)},
+		{body: randString(512<<10 - 1)},
+		{body: randString(512 << 10)},
+		{body: randString(512<<10 + 1)},
+		{body: randString(1<<20 - 1)},
+		{body: randString(1 << 20)},
+		{body: randString(1<<20 + 2)},
+	}
+
 	type reqInfo struct {
 	type reqInfo struct {
 		req   *http.Request
 		req   *http.Request
 		slurp []byte
 		slurp []byte