Skip to content

Commit 3a68d04

Browse files
authored
Merge pull request #1653 from onee-only/reuse-buffer
utils: merkletrie, Reuse buf on doCalculateHashForRegular. Fixes #1423
2 parents 9e863bc + 1cb55ba commit 3a68d04

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

utils/merkletrie/filesystem/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package filesystem
22

33
import (
4-
"io"
54
"os"
65
"path"
76

87
"github.com/go-git/go-git/v6/plumbing"
98
"github.com/go-git/go-git/v6/plumbing/filemode"
109
format "github.com/go-git/go-git/v6/plumbing/format/config"
10+
"github.com/go-git/go-git/v6/utils/ioutil"
1111
"github.com/go-git/go-git/v6/utils/merkletrie/noder"
1212

1313
"github.com/go-git/go-billy/v6"
@@ -180,7 +180,7 @@ func (n *node) doCalculateHashForRegular() plumbing.Hash {
180180
defer f.Close()
181181

182182
h := plumbing.NewHasher(format.SHA1, plumbing.BlobObject, n.size)
183-
if _, err := io.Copy(h, f); err != nil {
183+
if _, err := ioutil.CopyBufferPool(h, f); err != nil {
184184
return plumbing.ZeroHash
185185
}
186186

worktree_status_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/go-git/go-billy/v6/memfs"
910
"github.com/go-git/go-billy/v6/osfs"
11+
fixtures "github.com/go-git/go-git-fixtures/v5"
1012
"github.com/go-git/go-git/v6/plumbing/cache"
1113
"github.com/go-git/go-git/v6/storage/filesystem"
1214
"github.com/stretchr/testify/assert"
@@ -87,3 +89,25 @@ func TestIndexEntrySizeUpdatedForNonRegularFiles(t *testing.T) {
8789
// Check whether the index was updated with the two new line breaks.
8890
assert.Equal(t, uint32(len(content)+2), idx.Entries[0].Size)
8991
}
92+
93+
func BenchmarkWorktreeStatus(b *testing.B) {
94+
b.StopTimer()
95+
96+
f := fixtures.Basic().One()
97+
st := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
98+
99+
r, err := Open(st, memfs.New())
100+
require.NoError(b, err)
101+
102+
wt, err := r.Worktree()
103+
require.NoError(b, err)
104+
105+
err = wt.Reset(&ResetOptions{Mode: HardReset})
106+
require.NoError(b, err)
107+
108+
b.StartTimer()
109+
110+
for range b.N {
111+
wt.Status()
112+
}
113+
}

0 commit comments

Comments
 (0)