Better to move the throw to a dedicated method, it generates better code this way
*Hibernating Rhinos Ltd * Oren Eini* l CEO l *Mobile: + 972-52-548-6969 Office: +972-4-622-7811 *l *Fax: +972-153-4-622-7811 On Tue, Feb 28, 2017 at 9:21 AM, Van Den Berghe, Vincent < [email protected]> wrote: > Further testing has indicated that mapped memory accessors will throw an > exception if the position argument is already at the end, even if zero > bytes are read. > The methods mentioned previously therefore become: > > public override ByteBuffer Get(byte[] dst, int offset, int > length) > { > CheckBounds(offset, length, dst.Length); > if (length > Remaining) > throw new BufferUnderflowException(); > // we need to check for 0-length reads, since > ReadArray will throw an ArgumentOutOfRange exception if position is at the > end > // even when nothing is read > if (length > 0) > _accessor.ReadArray(Ix(NextGetIndex(length)), > dst, offset, length); > return this; > } > > > And > > public override ByteBuffer Put(byte[] src, int offset, int > length) > { > CheckBounds(offset, length, src.Length); > if (length > Remaining) > throw new BufferOverflowException(); > // we need to check for 0-length writes, since > ReadArray will throw an ArgumentOutOfRange exception if position is at the > end > // even when nothing is read > if (length > 0) > _accessor.WriteArray(Ix(NextPutIndex(length)), > src, offset, length); > return this; > } > > > Vincent >
