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

Faster string serialization by optimising packInt #489

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/main/java/org/mapdb/DataIO.java
Expand Up @@ -90,13 +90,17 @@ static public void packLong(DataOutput out, long value) throws IOException {
*/

static public void packInt(DataOutput out, int value) throws IOException {
//$DELAY$
int shift = 31-Integer.numberOfLeadingZeros(value);
shift -= shift%7; // round down to nearest multiple of 7
while(shift!=0){
out.writeByte((byte) (((value>>>shift) & 0x7F) | 0x80));
// Optimize for the common case where value is small. This is particular important where our caller
// is SerializerBase.SER_STRING.serialize because most chars will be ASCII characters and hence in this range.
if ((value & ~0x7F) != 0) {
//$DELAY$
shift-=7;
int shift = 31-Integer.numberOfLeadingZeros(value);
shift -= shift%7; // round down to nearest multiple of 7
while(shift!=0){
out.writeByte((byte) (((value>>>shift) & 0x7F) | 0x80));
//$DELAY$
shift-=7;
}
}
//$DELAY$
out.writeByte((byte) (value & 0x7F));
Expand Down