Created
January 22, 2015 07:05
-
-
Save minux/1bc4b50953e6c968ecb7 to your computer and use it in GitHub Desktop.
issue 9656: cmd/pack TestLargeDefs uses too much disk space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/cmd/pack/pack.go b/src/cmd/pack/pack.go | |
index f65ae0c..90152af 100644 | |
--- a/src/cmd/pack/pack.go | |
+++ b/src/cmd/pack/pack.go | |
@@ -426,20 +426,18 @@ func readPkgdef(file string) (data []byte, err error) { | |
// Read from file, collecting header for __.PKGDEF. | |
// The header is from the beginning of the file until a line | |
// containing just "!". The first line must begin with "go object ". | |
- rbuf := bufio.NewReader(f) | |
var wbuf bytes.Buffer | |
- for { | |
- line, err := rbuf.ReadBytes('\n') | |
- if err != nil { | |
- return nil, err | |
- } | |
- if wbuf.Len() == 0 && !bytes.HasPrefix(line, []byte("go object ")) { | |
+ scan := bufio.NewScanner(f) | |
+ for scan.Scan() { | |
+ line := scan.Text() | |
+ if wbuf.Len() == 0 && !strings.HasPrefix(line, ("go object ")) { | |
return nil, errors.New("not a Go object file") | |
} | |
- if bytes.Equal(line, []byte("!\n")) { | |
+ if line == "!" { | |
break | |
} | |
- wbuf.Write(line) | |
+ wbuf.WriteString(line) | |
+ wbuf.WriteString("\n") | |
} | |
return wbuf.Bytes(), nil | |
} | |
diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go | |
index cf6121f..0c58d62 100644 | |
--- a/src/cmd/pack/pack_test.go | |
+++ b/src/cmd/pack/pack_test.go | |
@@ -258,7 +258,7 @@ func TestLargeDefs(t *testing.T) { | |
} | |
printf("package large\n\ntype T struct {\n") | |
- for i := 0; i < 10000; i++ { | |
+ for i := 0; i < 1000; i++ { | |
printf("f%d int `tag:\"", i) | |
for j := 0; j < 100; j++ { | |
printf("t%d=%d,", j, j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment