blerer commented on code in PR #3348:
URL: https://github.com/apache/cassandra/pull/3348#discussion_r1627700355
##########
src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java:
##########
@@ -229,18 +231,40 @@ private List<ClusteringElements>
bindAndGetClusteringElements(QueryOptions optio
{
case SINGLE_COLUMN:
case TOKEN:
- return bindAndGet(options).stream()
- .map(b ->
ClusteringElements.of(columnsExpression.columnSpecification(), b))
- .collect(Collectors.toList());
+ return bindAndGetSingleTermClusteringElements(options);
case MULTI_COLUMN:
- return bindAndGetElements(options).stream()
- .map(buffers ->
ClusteringElements.of(columnsExpression.columns(), buffers))
-
.collect(Collectors.toList());
+ return bindAndGetMultiTermClusteringElements(options);
default:
throw new UnsupportedOperationException();
}
}
+ private List<ClusteringElements>
bindAndGetSingleTermClusteringElements(QueryOptions options)
+ {
+ List<ByteBuffer> values = bindAndGet(options);
+ if (!values.isEmpty())
+ {
+ List<ClusteringElements> elements = new ArrayList<>(values.size());
+ for (ByteBuffer value : values)
Review Comment:
If we are concerned about allocations at this place, we should use a `for
(int i = , m = values.size(); i < m; i++)` loop. We replaced those loops in the
past already for the same reason.
##########
src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java:
##########
@@ -229,18 +231,40 @@ private List<ClusteringElements>
bindAndGetClusteringElements(QueryOptions optio
{
case SINGLE_COLUMN:
case TOKEN:
- return bindAndGet(options).stream()
- .map(b ->
ClusteringElements.of(columnsExpression.columnSpecification(), b))
- .collect(Collectors.toList());
+ return bindAndGetSingleTermClusteringElements(options);
case MULTI_COLUMN:
- return bindAndGetElements(options).stream()
- .map(buffers ->
ClusteringElements.of(columnsExpression.columns(), buffers))
-
.collect(Collectors.toList());
+ return bindAndGetMultiTermClusteringElements(options);
default:
throw new UnsupportedOperationException();
}
}
+ private List<ClusteringElements>
bindAndGetSingleTermClusteringElements(QueryOptions options)
+ {
+ List<ByteBuffer> values = bindAndGet(options);
+ if (!values.isEmpty())
+ {
+ List<ClusteringElements> elements = new ArrayList<>(values.size());
+ for (ByteBuffer value : values)
+
elements.add(ClusteringElements.of(columnsExpression.columnSpecification(),
value));
+ return Collections.unmodifiableList(elements);
Review Comment:
There is no need to wrap the list into an unmodifiable list.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]