This is an automated email from the ASF dual-hosted git repository. jorgebg pushed a commit to branch TINKERPOP-1942 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/TINKERPOP-1942 by this push: new 27b5277 Use local buffer pool for byte codes 27b5277 is described below commit 27b52775426be9f637d2b266a2d1e439a15149cb Author: Jorge Bay Gondra <jorgebaygon...@gmail.com> AuthorDate: Tue Dec 18 10:00:39 2018 +0100 Use local buffer pool for byte codes --- .../org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java | 9 +++++++++ .../tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java index 4087fb0..a50a981 100644 --- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java +++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java @@ -87,10 +87,12 @@ public enum DataType { private final int code; private static final Map<Integer, DataType> typeByCode = new HashMap<>(); + private static final Map<DataType, byte[]> bufferByDataType = new HashMap<>(); static { for (DataType t : DataType.values()) { typeByCode.put(t.code, t); + bufferByDataType.put(t, new byte[] { (byte)t.code }); } } @@ -113,6 +115,13 @@ public enum DataType { } /** + * Gets a byte array containing a single byte representing the type code. + */ + byte[] getDataTypeBuffer() { + return bufferByDataType.get(this); + } + + /** * Gets a DataType by code. */ public static DataType get(final int code) { diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java index a785f37..b3c2c0f 100644 --- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java +++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java @@ -90,8 +90,7 @@ public class GraphBinaryWriter { return allocator.compositeBuffer(2).addComponents(true, // {type_code} - // TODO: Reuse buffer pooled locally - allocator.buffer(1).writeByte(serializer.getDataType().getCodeByte()), + Unpooled.wrappedBuffer(serializer.getDataType().getDataTypeBuffer()), // {type_info}{value_flag}{value} serializer.write(value, allocator, this)); } @@ -103,7 +102,6 @@ public class GraphBinaryWriter { */ public <T> ByteBuf writeFullyQualifiedNull(final Class<T> objectClass, final ByteBufAllocator allocator, final Object information) throws SerializationException { TypeSerializer<T> serializer = registry.getSerializer(objectClass); - //TODO: Change to writeNull() return serializer.write(null, allocator, this); }