From 5598068360a39a61d97887522e474323d8f78f97 Mon Sep 17 00:00:00 2001 From: Arran Walker Date: Sun, 21 Apr 2019 12:35:35 +0000 Subject: 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 --- utils/binary/read.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'utils/binary/read.go') 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 { -- cgit