[ 
https://issues.apache.org/jira/browse/CASSANDRA-1998?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12982813#action_12982813
 ] 

Sylvain Lebresne commented on CASSANDRA-1998:
---------------------------------------------

Right, but we hardly really want the index given to BB.get() to be less than 
BB.position().
My point here is that for most of our ByteBuffer uses (and by that I exclude 
the buffer 
of BufferedRandomAccessFile for instance), we consider a byteBuffer to be the 
underlying
byte array from position to limit. So this patch tries to make the usage more 
like (I think) we 
would want it to be, than how the ByteBuffer api does it.

I agree, this is debatable, but I do believe this makes the code cleaner et 
easier to reason
about. For instance, if you stick to the functions of ByteBufferUtil, your 
indexes always go 
from 0 to BB.remaining() which is much more natural 99% of the time.
(for the story, my first patch for #1999 used BB.remaining() instead BB.limit() 
because I though
"I need the subarray from index to the end, so the length should remaining() - 
index" but wrong
because the index was actually not relative to the ByteBuffer position.

Anyway, again that is debatable (but I'd recall that almost all patch dealing 
with ByteBuffer got 
a few leading tickets fixing mistakes with offset, so simplifying this seems 
worthy to me).

> Make offsets in ByteBufferUtil.* methods relatif to the ByteBuffer position()
> -----------------------------------------------------------------------------
>
>                 Key: CASSANDRA-1998
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-1998
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 0.8
>            Reporter: Sylvain Lebresne
>            Assignee: Sylvain Lebresne
>            Priority: Minor
>             Fix For: 0.8
>
>         Attachments: 0001-0.7-Make-BB-offset-relative-to-position.patch, 
> 0001-Make-BB-offset-relative-to-position.patch, 
> 0002-0.7-Move-EMPTY_BYTE_BUFFER-to-ByteBufferUtil.patch, 
> 0002-Move-EMPTY_BYTE_BUFFER-to-ByteBufferUtil.patch
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> A few methods in ByteBufferUtil take as parameter an offset inside a
> ByteBuffer. When we use them, we always want this offset to be relative to
> ByteBuffer.position(), but it is not, it is relative to the ByteBuffer 0
> position. I argue this is not inline with the way we use ByteBuffers and as a
> consequence, is ugly and error-prone.
> This ticket proposes to make the offset of the ByteBufferUtil.* methods
> relatif to the ByteBuffer position.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to