]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip: remove an allocation, speed up a test
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Aug 2013 21:48:08 +0000 (14:48 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Aug 2013 21:48:08 +0000 (14:48 -0700)
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

src/pkg/archive/zip/reader.go
src/pkg/archive/zip/zip_test.go

index 4221a826c07387e99f3fdf01faa577cdd23297e4..499215328f0546afc436f73b1ae26090d6341893 100644 (file)
@@ -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
 // and returns the file body offset.
 func (f *File) findBodyOffset() (int64, error) {
-       r := io.NewSectionReader(f.zipr, f.headerOffset, f.zipsize-f.headerOffset)
        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
        }
        b := readBuf(buf[:])
index a8af206a88fcfa1e9a4a5ba1c066285110bc2b77..870f0431442f9bbce670b05290a5c7722575ff06 100644 (file)
@@ -17,14 +17,14 @@ import (
 )
 
 func TestOver65kFiles(t *testing.T) {
-       if testing.Short() {
-               t.Skip("slow test; skipping")
-       }
        buf := new(bytes.Buffer)
        w := NewWriter(buf)
        const nFiles = (1 << 16) + 42
        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 {
                        t.Fatalf("creating file %d: %v", i, err)
                }