[
https://issues.apache.org/jira/browse/LUCENE-4674?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13549542#comment-13549542
]
Shai Erera commented on LUCENE-4674:
------------------------------------
I recently (LUCENE-4620) moved some facets code to use BytesRef and IntsRef and
found these two classes very convenient. The only thing that I found missing is
a *Ref.upto. E.g., I first made the mistake {{for (int i = bytes.offset; i <
bytes.length; i++)}}, where the correct form is {{for (int i = bytes.offset; i
< bytes.length + bytes.offset; i++)}} (but then you need to do that '+' at
every iteration, or extract it to a variable).
I considered using BytesBuffer instead, but as long as e.g. a Payload is
represented as a BytesRef, it's a waste to always
ByteBuffer.wrap(BytesRef.bytes, offset, length). I used BytesRef as it was very
convenient (and if we add an 'upto' index to them, that'd even be greater :)).
I agree that grow() is currently risky, as it may override some data that is
used by another thread (as a slice to the buffer). But that can be solved with
proper documentation I think.
I also agree that we should not set offset to 0. I did that, and MemoryCodec
got upset :). For all practical purposes, apps should treat offset and length
as final (we should not make them final though, just document it). If an app
messes with them, it should better know what it's doing.
> Consistently set offset=0 in BytesRef.copyBytes
> -----------------------------------------------
>
> Key: LUCENE-4674
> URL: https://issues.apache.org/jira/browse/LUCENE-4674
> Project: Lucene - Core
> Issue Type: Task
> Reporter: Adrien Grand
> Assignee: Adrien Grand
> Priority: Minor
> Attachments: LUCENE-4674.patch
>
>
> BytesRef.copyBytes(BytesRef other) has two branches:
> - either the destination array is large enough and it will copy bytes after
> offset,
> - or it needs to resize and in that case it will set offset = 0.
> I think this method should always set offset = 0 for consistency, and to
> avoid resizing when other.length is larger than this.bytes.length -
> this.offset but smaller than this.bytes.length.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]