alexdegroot commented on issue #45559: URL: https://github.com/apache/arrow/issues/45559#issuecomment-2678124449
I've created a [PR](https://github.com/apache/arrow/pull/45609) which solves the arrow allocation on every call. It could be further optimized by using a shift operator: ``` public static bool GetBit(ReadOnlySpan<byte> data, int index) => (data[index / 8] & (1 << (index % 8))) != 0; ``` Unfortunately, this will break this contract: ``` [Theory] [InlineData(null, 0)] [InlineData(new byte[] { 0b00000000 }, -1)] public void ThrowsWhenBitIndexOutOfRange(byte[] data, int index) { Assert.Throws<IndexOutOfRangeException>(() => BitUtility.GetBit(data, index)); } ``` I'm curious though if that contract makes sense. The other overload of the method(although only used for test purposes), doesn't throw and fails therefore: ``` [Theory] [InlineData(0b_11110011, 0)] [InlineData(0b_11110011, -1)] public void ThrowsWhenBitIndexOutOfRange_ByteOverload(byte data, int index) { Assert.Throws<IndexOutOfRangeException>(() => BitUtility.GetBit(data, index)); } ``` Proposal: either accept my PR or let me create a new one where I include both fixes: 1. Remove the ThrowsWhenBitIndexOutOfRange-tests 2. Use the shift operator @CurtHagenlocher maybe you can shine a light on this? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
