Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ByteBuffer#compact does not follow Java's ByteBuffer's compact? #73

Open
vmirage opened this issue Apr 10, 2016 · 1 comment
Open

ByteBuffer#compact does not follow Java's ByteBuffer's compact? #73

vmirage opened this issue Apr 10, 2016 · 1 comment

Comments

@vmirage
Copy link

vmirage commented Apr 10, 2016

Is there any reason why the compact function does not follow the Java's ByteBuffer's compact method?

Where currently it does:

Compacts this ByteBuffer to be backed by a ByteBuffer#buffer of its contents' length. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will set offset = 0 and limit = capacity and adapt ByteBuffer#markedOffset to the same relative position if set.

While in Java it does:

The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.

The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.

@dcodeIO
Copy link
Member

dcodeIO commented Apr 10, 2016

There is no specific reason. The current implementation is simply what I needed, and I took the term "compact" for it. I see, however, that there is no easy alternative available currently. Could be added, of course, something like ByteBuffer#move(offset=0) (named after memmove).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants