Skip to content

Commit

Permalink
Update value size calculation for generic key state with more compact…
Browse files Browse the repository at this point in the history
… number serialization
  • Loading branch information
burqen committed Aug 16, 2018
1 parent fdb5523 commit 05947db
Showing 1 changed file with 29 additions and 3 deletions.
Expand Up @@ -87,7 +87,12 @@ class GenericKeyState extends TemporalValueWriterAdapter<RuntimeException>
Long.BYTES; /* days */
private static final int SIZE_BOOLEAN = Byte.BYTES; /* byte for this boolean value */
private static final int SIZE_NUMBER_TYPE = Byte.BYTES; /* type of value */
private static final int SIZE_NUMBER = Long.BYTES; /* raw value bits */
private static final int SIZE_NUMBER_BYTE = Byte.BYTES; /* raw value bits */
private static final int SIZE_NUMBER_SHORT = Short.BYTES; /* raw value bits */
private static final int SIZE_NUMBER_INT = Integer.BYTES; /* raw value bits */
private static final int SIZE_NUMBER_LONG = Long.BYTES; /* raw value bits */
private static final int SIZE_NUMBER_FLOAT = Integer.BYTES; /* raw value bits */
private static final int SIZE_NUMBER_DOUBLE = Long.BYTES; /* raw value bits */
private static final int SIZE_ARRAY_LENGTH = Integer.BYTES;
private static final int BIGGEST_REASONABLE_ARRAY_LENGTH = PAGE_SIZE / 2 / Integer.SIZE;

Expand Down Expand Up @@ -436,7 +441,7 @@ private int valueSize()
case BOOLEAN:
return SIZE_BOOLEAN;
case NUMBER:
return SIZE_NUMBER + SIZE_NUMBER_TYPE;
return numberKeySize( long1 ) + SIZE_NUMBER_TYPE;
case ZONED_DATE_TIME_ARRAY:
return arrayKeySize( SIZE_ZONED_DATE_TIME );
case LOCAL_DATE_TIME_ARRAY:
Expand All @@ -460,12 +465,33 @@ private int valueSize()
case BOOLEAN_ARRAY:
return arrayKeySize( SIZE_BOOLEAN );
case NUMBER_ARRAY:
return arrayKeySize( SIZE_NUMBER ) + SIZE_NUMBER_TYPE;
return arrayKeySize( numberKeySize( long1 ) ) + SIZE_NUMBER_TYPE;
default:
throw new IllegalArgumentException( "Unknown type " + type );
}
}

private static int numberKeySize( long long1 )
{
switch ( (int) long1 )
{
case RawBits.BYTE:
return SIZE_NUMBER_BYTE;
case RawBits.SHORT:
return SIZE_NUMBER_SHORT;
case RawBits.INT:
return SIZE_NUMBER_INT;
case RawBits.LONG:
return SIZE_NUMBER_LONG;
case RawBits.FLOAT:
return SIZE_NUMBER_FLOAT;
case RawBits.DOUBLE:
return SIZE_NUMBER_DOUBLE;
default:
throw new IllegalArgumentException( "Unknown number type " + long1 );
}
}

private int arrayKeySize( int elementSize )
{
return SIZE_ARRAY_LENGTH + arrayLength * elementSize;
Expand Down

0 comments on commit 05947db

Please sign in to comment.