This is an automated email from the ASF dual-hosted git repository. smiklosovic pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push: new 87ee1ac7d2 Replace Stream iteration with for-loop for SimpleRestriction::bindAndGetClusteringElements 87ee1ac7d2 is described below commit 87ee1ac7d291d64c08f7724c343a51f4e883b123 Author: samueldlightfoot <samueldlightf...@gmail.com> AuthorDate: Wed Jun 5 08:05:25 2024 +0100 Replace Stream iteration with for-loop for SimpleRestriction::bindAndGetClusteringElements patch by Samuel Lightfoot; reviewed by Stefan Miklosovic and Benjamin Lerer for CASSANDRA-19679 --- CHANGES.txt | 1 + .../cql3/restrictions/SimpleRestriction.java | 34 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2dcbb6982b..dcb65b604b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 5.1 + * Replace Stream iteration with for-loop for SimpleRestriction::bindAndGetClusteringElements (CASSANDRA-19679) * Consolidate logging on trace level (CASSANDRA-19632) * Expand DDL statements on coordinator before submission to the CMS (CASSANDRA-19592) * Fix number of arguments of String.format() in various classes (CASSANDRA-19645) diff --git a/src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java b/src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java index 1a4a4f3935..0898cacf43 100644 --- a/src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java +++ b/src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java @@ -19,6 +19,8 @@ package org.apache.cassandra.cql3.restrictions; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -229,18 +231,38 @@ public final class SimpleRestriction implements SingleRestriction { 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()) + return Collections.emptyList(); + + List<ClusteringElements> elements = new ArrayList<>(values.size()); + for (int i = 0; i < values.size(); i++) + elements.add(ClusteringElements.of(columnsExpression.columnSpecification(), values.get(i))); + return elements; + } + + private List<ClusteringElements> bindAndGetMultiTermClusteringElements(QueryOptions options) + { + List<List<ByteBuffer>> values = bindAndGetElements(options); + if (values.isEmpty()) + return Collections.emptyList(); + + List<ClusteringElements> elements = new ArrayList<>(values.size()); + for (int i = 0; i < values.size(); i++) + elements.add(ClusteringElements.of(columnsExpression.columns(), values.get(i))); + return elements; + } + private List<ByteBuffer> bindAndGet(QueryOptions options) { List<ByteBuffer> buffers = values.bindAndGet(options); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org