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

pre-allocate the results size #3089

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions src/main/java/redis/clients/jedis/graph/ResultSetBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,41 +129,42 @@ public Iterator<Record> iterator() {
@SuppressWarnings("unchecked")
private List<Record> parseRecords(Header header, Object data) {
List<List<Object>> rawResultSet = (List<List<Object>>) data;
List<Record> results = new ArrayList<>();

if (rawResultSet == null || rawResultSet.isEmpty()) {
return results;
} else {
// go over each raw result
for (List<Object> row : rawResultSet) {

List<Object> parsedRow = new ArrayList<>(row.size());
// go over each object in the result
for (int i = 0; i < row.size(); i++) {
// get raw representation of the object
List<Object> obj = (List<Object>) row.get(i);
// get object type
ResultSet.ColumnType objType = header.getSchemaTypes().get(i);
// deserialize according to type and
switch (objType) {
case NODE:
parsedRow.add(deserializeNode(obj));
break;
case RELATION:
parsedRow.add(deserializeEdge(obj));
break;
case SCALAR:
parsedRow.add(deserializeScalar(obj));
break;
default:
parsedRow.add(null);
break;
}

return new ArrayList<>(0);
}

// go over each raw result
List<Record> results = new ArrayList<>(rawResultSet.size());
for (List<Object> row : rawResultSet) {

List<Object> parsedRow = new ArrayList<>(row.size());
// go over each object in the result
for (int i = 0; i < row.size(); i++) {
// get raw representation of the object
List<Object> obj = (List<Object>) row.get(i);
// get object type
ResultSet.ColumnType objType = header.getSchemaTypes().get(i);
// deserialize according to type and
switch (objType) {
case NODE:
parsedRow.add(deserializeNode(obj));
break;
case RELATION:
parsedRow.add(deserializeEdge(obj));
break;
case SCALAR:
parsedRow.add(deserializeScalar(obj));
break;
default:
parsedRow.add(null);
break;
}
// create new record from deserialized objects
Record record = new RecordImpl(header.getSchemaNames(), parsedRow);
results.add(record);

}
// create new record from deserialized objects
Record record = new RecordImpl(header.getSchemaNames(), parsedRow);
results.add(record);
}
return results;
}
Expand Down