Skip to content

Commit

Permalink
Don't recreate array in hot path
Browse files Browse the repository at this point in the history
`ValueType::values` creates a new array on each call, store it in
a static constant instead.
  • Loading branch information
pontusmelke committed Oct 23, 2018
1 parent 0f5efb6 commit 7b54318
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -118,6 +118,7 @@ public class AppendOnlyValuesContainer implements ValuesContainer
{
private static final int CHUNK_SIZE = (int) ByteUnit.kibiBytes( 512 );
private static final int REMOVED = 0xFF;
private static final ValueType[] VALUE_TYPES = ValueType.values();

private final int chunkSize;
private final List<ByteBuffer> chunks = new ArrayList<>();
Expand Down Expand Up @@ -170,10 +171,10 @@ public Value get( long ref )
checkArgument( offset >= 0 && offset < chunk.position(), "invalid chunk offset (%d), ref: 0x%X", offset, ref );
final int typeId = chunk.get( offset ) & 0xFF;
checkArgument( typeId != REMOVED, "element is already removed, ref: 0x%X", ref );
checkArgument( typeId < ValueType.values().length, "invaling typeId (%d) for ref 0x%X", typeId, ref );
checkArgument( typeId < VALUE_TYPES.length, "invaling typeId (%d) for ref 0x%X", typeId, ref );
offset++;

final ValueType type = ValueType.values()[typeId];
final ValueType type = VALUE_TYPES[typeId];
return type.getReader().read( chunk, offset );
}

Expand Down

0 comments on commit 7b54318

Please sign in to comment.