diff options
author | Arran Walker <arran.walker@fiveturns.org> | 2019-04-21 12:35:35 +0000 |
---|---|---|
committer | Arran Walker <arran.walker@fiveturns.org> | 2019-04-21 14:38:51 +0000 |
commit | 5598068360a39a61d97887522e474323d8f78f97 (patch) | |
tree | 172273171aecb62b97b2c17b7b2c82211cfd131b /utils | |
parent | e5268e9c3c94f60e3c2008dc2ab4762c75352bfc (diff) | |
download | go-git-5598068360a39a61d97887522e474323d8f78f97.tar.gz |
plumbing: format/index perf, buffered reads, reflection removal
Large performance increase by buffering reads.
There were a few instances where binary.Read() would end up using reflection on
&plumbing.Hash, rather than treating it as a byte slice. This has now been
resolved.
Signed-off-by: Arran Walker <arran.walker@fiveturns.org>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/binary/read.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/utils/binary/read.go b/utils/binary/read.go index 50da1ff..ac55609 100644 --- a/utils/binary/read.go +++ b/utils/binary/read.go @@ -25,6 +25,15 @@ func Read(r io.Reader, data ...interface{}) error { // ReadUntil reads from r untin delim is found func ReadUntil(r io.Reader, delim byte) ([]byte, error) { + if bufr, ok := r.(*bufio.Reader); ok { + value, err := bufr.ReadBytes(delim) + if err != nil || len(value) == 0 { + return nil, err + } + + return value[:len(value)-1], nil + } + var buf [1]byte value := make([]byte, 0, 16) for { |