From e5defa4d356116f6f92e171cbd0691635d94afea Mon Sep 17 00:00:00 2001 From: Frederic Langlet Date: Wed, 8 Nov 2023 15:34:29 +0100 Subject: [PATCH] Speed optimization --- v2/bitstream/DefaultInputBitStream.go | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/v2/bitstream/DefaultInputBitStream.go b/v2/bitstream/DefaultInputBitStream.go index f6fc944e..8ac0f4c9 100644 --- a/v2/bitstream/DefaultInputBitStream.go +++ b/v2/bitstream/DefaultInputBitStream.go @@ -147,12 +147,39 @@ func (this *DefaultInputBitStream) ReadArray(bits []byte, count uint) uint { } else { // Not byte aligned r := 64 - this.availBits + a := this.availBits + + for remaining >= 256 { + v0 := this.current + + if this.position+32 > this.maxPosition { + this.pullCurrent() + this.availBits -= r + binary.BigEndian.PutUint64(bits[start:start+8], (v0<>uint(this.availBits))) + start += 8 + remaining -= 64 + continue + } + + v1 := binary.BigEndian.Uint64(this.buffer[this.position:]) + v2 := binary.BigEndian.Uint64(this.buffer[this.position+8:]) + v3 := binary.BigEndian.Uint64(this.buffer[this.position+16:]) + v4 := binary.BigEndian.Uint64(this.buffer[this.position+24:]) + this.position += 32 + binary.BigEndian.PutUint64(bits[start:], (v0<>a)) + binary.BigEndian.PutUint64(bits[start+8:], (v1<>a)) + binary.BigEndian.PutUint64(bits[start+16:], (v2<>a)) + binary.BigEndian.PutUint64(bits[start+24:], (v3<>a)) + start += 32 + remaining -= 256 + this.current = v4 + } for remaining >= 64 { - v := this.current & ((uint64(1) << this.availBits) - 1) + v := this.current this.pullCurrent() this.availBits -= r - binary.BigEndian.PutUint64(bits[start:start+8], (v<>uint(this.availBits))) + binary.BigEndian.PutUint64(bits[start:start+8], (v<>uint(this.availBits))) start += 8 remaining -= 64 }