@@ -140,26 +140,28 @@ public Header getHeader() {
140140 */
141141 @ SuppressWarnings ("unchecked" )
142142 private Node deserializeNode (List <Object > rawNodeData ) {
143- Node node = new Node ();
144- deserializeGraphEntityId (node , rawNodeData .get (0 ));
143+
145144 List <Long > labelsIndices = (List <Long >) rawNodeData .get (1 );
145+ List <List <Object >> rawProperties = (List <List <Object >>) rawNodeData .get (2 );
146+
147+ Node node = new Node (labelsIndices .size (), rawProperties .size ());
148+ deserializeGraphEntityId (node , (Long ) rawNodeData .get (0 ));
149+
146150 for (Long labelIndex : labelsIndices ) {
147151 String label = cache .getLabel (labelIndex .intValue (), redisGraph );
148152 node .addLabel (label );
149153 }
150- deserializeGraphEntityProperties (node , (List <List <Object >>) rawNodeData .get (2 ));
151154
152- return node ;
155+ deserializeGraphEntityProperties ( node , rawProperties ) ;
153156
157+ return node ;
154158 }
155159
156160 /**
157161 * @param graphEntity graph entity
158- * @param rawEntityId raw representation of entity id to be set to the graph
159- * entity
162+ * @param id entity id to be set to the graph entity
160163 */
161- private void deserializeGraphEntityId (GraphEntity graphEntity , Object rawEntityId ) {
162- long id = (Long ) rawEntityId ;
164+ private void deserializeGraphEntityId (GraphEntity graphEntity , long id ) {
163165 graphEntity .setId (id );
164166 }
165167
@@ -172,16 +174,19 @@ private void deserializeGraphEntityId(GraphEntity graphEntity, Object rawEntityI
172174 */
173175 @ SuppressWarnings ("unchecked" )
174176 private Edge deserializeEdge (List <Object > rawEdgeData ) {
175- Edge edge = new Edge ();
176- deserializeGraphEntityId (edge , rawEdgeData .get (0 ));
177+
178+ List <List <Object >> rawProperties = (List <List <Object >>) rawEdgeData .get (4 );
179+
180+ Edge edge = new Edge (rawProperties .size ());
181+ deserializeGraphEntityId (edge , (Long ) rawEdgeData .get (0 ));
177182
178183 String relationshipType = cache .getRelationshipType (((Long ) rawEdgeData .get (1 )).intValue (), redisGraph );
179184 edge .setRelationshipType (relationshipType );
180185
181186 edge .setSource ((long ) rawEdgeData .get (2 ));
182187 edge .setDestination ((long ) rawEdgeData .get (3 ));
183188
184- deserializeGraphEntityProperties (edge , ( List < List < Object >>) rawEdgeData . get ( 4 ) );
189+ deserializeGraphEntityProperties (edge , rawProperties );
185190
186191 return edge ;
187192 }
@@ -256,8 +261,11 @@ private Object deserializePoint(Object rawScalarData) {
256261 @ SuppressWarnings ("unchecked" )
257262 private Map <String , Object > deserializeMap (Object rawScalarData ) {
258263 List <Object > keyTypeValueEntries = (List <Object >) rawScalarData ;
259- Map <String , Object > map = new HashMap <>();
260- for (int i = 0 ; i < keyTypeValueEntries .size (); i += 2 ) {
264+
265+ int size = keyTypeValueEntries .size ();
266+ Map <String , Object > map = new HashMap <>(size >> 1 ); // set the capacity to half of the list
267+
268+ for (int i = 0 ; i < size ; i += 2 ) {
261269 String key = SafeEncoder .encode ((byte []) keyTypeValueEntries .get (i ));
262270 Object value = deserializeScalar ((List <Object >) keyTypeValueEntries .get (i + 1 ));
263271 map .put (key , value );
0 commit comments