-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Update to Slice 2.0 #18471
Merged
Merged
Update to Slice 2.0 #18471
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,6 +243,91 @@ public void writeBytes(byte[] source, int sourceIndex, int length) | |
uncompressedSize += length; | ||
} | ||
|
||
@Override | ||
public void writeShorts(short[] source, int sourceIndex, int length) | ||
{ | ||
WriteBuffer buffer = buffers[0]; | ||
int currentIndex = sourceIndex; | ||
int shortsRemaining = length; | ||
while (shortsRemaining > 0) { | ||
ensureCapacityFor(min(Long.BYTES, shortsRemaining * Short.BYTES)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
int bufferCapacity = buffer.remainingCapacity(); | ||
int shortsToCopy = min(shortsRemaining, bufferCapacity / Short.BYTES); | ||
buffer.writeShorts(source, currentIndex, shortsToCopy); | ||
currentIndex += shortsToCopy; | ||
shortsRemaining -= shortsToCopy; | ||
} | ||
uncompressedSize += length * Short.BYTES; | ||
} | ||
|
||
@Override | ||
public void writeInts(int[] source, int sourceIndex, int length) | ||
{ | ||
WriteBuffer buffer = buffers[0]; | ||
int currentIndex = sourceIndex; | ||
int intsRemaining = length; | ||
while (intsRemaining > 0) { | ||
ensureCapacityFor(min(Long.BYTES, intsRemaining * Integer.BYTES)); | ||
int bufferCapacity = buffer.remainingCapacity(); | ||
int intsToCopy = min(intsRemaining, bufferCapacity / Integer.BYTES); | ||
buffer.writeInts(source, currentIndex, intsToCopy); | ||
currentIndex += intsToCopy; | ||
intsRemaining -= intsToCopy; | ||
} | ||
uncompressedSize += length * Integer.BYTES; | ||
} | ||
|
||
@Override | ||
public void writeLongs(long[] source, int sourceIndex, int length) | ||
{ | ||
WriteBuffer buffer = buffers[0]; | ||
int currentIndex = sourceIndex; | ||
int longsRemaining = length; | ||
while (longsRemaining > 0) { | ||
ensureCapacityFor(min(Long.BYTES, longsRemaining * Long.BYTES)); | ||
int bufferCapacity = buffer.remainingCapacity(); | ||
int longsToCopy = min(longsRemaining, bufferCapacity / Long.BYTES); | ||
buffer.writeLongs(source, currentIndex, longsToCopy); | ||
currentIndex += longsToCopy; | ||
longsRemaining -= longsToCopy; | ||
} | ||
uncompressedSize += length * Long.BYTES; | ||
} | ||
|
||
@Override | ||
public void writeFloats(float[] source, int sourceIndex, int length) | ||
{ | ||
WriteBuffer buffer = buffers[0]; | ||
int currentIndex = sourceIndex; | ||
int floatsRemaining = length; | ||
while (floatsRemaining > 0) { | ||
ensureCapacityFor(min(Long.BYTES, floatsRemaining * Float.BYTES)); | ||
int bufferCapacity = buffer.remainingCapacity(); | ||
int floatsToCopy = min(floatsRemaining, bufferCapacity / Float.BYTES); | ||
buffer.writeFloats(source, currentIndex, floatsToCopy); | ||
currentIndex += floatsToCopy; | ||
floatsRemaining -= floatsToCopy; | ||
} | ||
uncompressedSize += length * Float.BYTES; | ||
} | ||
|
||
@Override | ||
public void writeDoubles(double[] source, int sourceIndex, int length) | ||
{ | ||
WriteBuffer buffer = buffers[0]; | ||
int currentIndex = sourceIndex; | ||
int doublesRemaining = length; | ||
while (doublesRemaining > 0) { | ||
ensureCapacityFor(min(Long.BYTES, doublesRemaining * Double.BYTES)); | ||
int bufferCapacity = buffer.remainingCapacity(); | ||
int doublesToCopy = min(doublesRemaining, bufferCapacity / Double.BYTES); | ||
buffer.writeDoubles(source, currentIndex, doublesToCopy); | ||
currentIndex += doublesToCopy; | ||
doublesRemaining -= doublesToCopy; | ||
} | ||
uncompressedSize += length * Double.BYTES; | ||
} | ||
|
||
public Slice closePage() | ||
{ | ||
compress(); | ||
|
@@ -589,6 +674,36 @@ public void writeBytes(byte[] source, int sourceIndex, int length) | |
position += length; | ||
} | ||
|
||
public void writeShorts(short[] source, int sourceIndex, int length) | ||
{ | ||
slice.setShorts(position, source, sourceIndex, length); | ||
position += length * Short.BYTES; | ||
} | ||
|
||
public void writeInts(int[] source, int sourceIndex, int length) | ||
{ | ||
slice.setInts(position, source, sourceIndex, length); | ||
position += length * Integer.BYTES; | ||
} | ||
|
||
public void writeLongs(long[] source, int sourceIndex, int length) | ||
{ | ||
slice.setLongs(position, source, sourceIndex, length); | ||
position += length * Long.BYTES; | ||
} | ||
|
||
public void writeFloats(float[] source, int sourceIndex, int length) | ||
{ | ||
slice.setFloats(position, source, sourceIndex, length); | ||
position += length * Float.BYTES; | ||
} | ||
|
||
public void writeDoubles(double[] source, int sourceIndex, int length) | ||
{ | ||
slice.setDoubles(position, source, sourceIndex, length); | ||
position += length * Double.BYTES; | ||
} | ||
|
||
public void skip(int length) | ||
{ | ||
position += length; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this line. If there are, say, 100 shorts remaining, this would do:
ensureReadable(min(8, 200))
->ensureReadable(8)
Also, what's the significance of
Long.BYTES
here? Why would this method care about having at least 8 readable bytes, assuming that's the intention?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely agree. This is the style of the other methods in this class I had to ask @arhimondr how this code works, and this is what he said:
I think we all agree it need some renaming