Commit c7d352c9 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

archive/zip: remove an allocation, speed up a test

Update #6138

TestOver65kFiles spends all its time garbage collecting.
Removing the 1.4 MB of allocations per each of the 65k
files brings this from 34 seconds to 0.23 seconds.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/12894043
parent c18af467
...@@ -179,9 +179,8 @@ func (r *checksumReader) Close() error { return r.rc.Close() } ...@@ -179,9 +179,8 @@ func (r *checksumReader) Close() error { return r.rc.Close() }
// findBodyOffset does the minimum work to verify the file has a header // findBodyOffset does the minimum work to verify the file has a header
// and returns the file body offset. // and returns the file body offset.
func (f *File) findBodyOffset() (int64, error) { func (f *File) findBodyOffset() (int64, error) {
r := io.NewSectionReader(f.zipr, f.headerOffset, f.zipsize-f.headerOffset)
var buf [fileHeaderLen]byte var buf [fileHeaderLen]byte
if _, err := io.ReadFull(r, buf[:]); err != nil { if _, err := f.zipr.ReadAt(buf[:], f.headerOffset); err != nil {
return 0, err return 0, err
} }
b := readBuf(buf[:]) b := readBuf(buf[:])
......
...@@ -17,14 +17,14 @@ import ( ...@@ -17,14 +17,14 @@ import (
) )
func TestOver65kFiles(t *testing.T) { func TestOver65kFiles(t *testing.T) {
if testing.Short() {
t.Skip("slow test; skipping")
}
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
w := NewWriter(buf) w := NewWriter(buf)
const nFiles = (1 << 16) + 42 const nFiles = (1 << 16) + 42
for i := 0; i < nFiles; i++ { for i := 0; i < nFiles; i++ {
_, err := w.Create(fmt.Sprintf("%d.dat", i)) _, err := w.CreateHeader(&FileHeader{
Name: fmt.Sprintf("%d.dat", i),
Method: Store, // avoid Issue 6136 and Issue 6138
})
if err != nil { if err != nil {
t.Fatalf("creating file %d: %v", i, err) t.Fatalf("creating file %d: %v", i, err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment