diff --git a/CHANGES.txt b/CHANGES.txt index 3e63e11f67..afda96a8f7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 5.1 + * Improve performance of DistributedSchema.validate for large schemas (CASSANDRA-20360) * Add JSON constraint (CASSANDRA-20273) * Prevent invalid constraint combinations (CASSANDRA-20330) * Support CREATE TABLE LIKE WITH INDEXES (CASSANDRA-19965) diff --git a/src/java/org/apache/cassandra/utils/btree/AbstractBTreeMap.java b/src/java/org/apache/cassandra/utils/btree/AbstractBTreeMap.java index 0db33a52cc..3d0baf08f1 100644 --- a/src/java/org/apache/cassandra/utils/btree/AbstractBTreeMap.java +++ b/src/java/org/apache/cassandra/utils/btree/AbstractBTreeMap.java @@ -18,13 +18,15 @@ package org.apache.cassandra.utils.btree; +import java.util.AbstractCollection; import java.util.AbstractMap; +import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.Map; import java.util.Set; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterators; public abstract class AbstractBTreeMap extends AbstractMap { @@ -105,13 +107,27 @@ public abstract class AbstractBTreeMap extends AbstractMap return keySet; } + /** + * This method, according to the contract of {@link Map#values()}, returns a collection backed by the map. It also + * closely mirrors {@link AbstractMap#values()}, which returns an {@link AbstractCollection}. + */ @Override - public Set values() + public Collection values() { - ImmutableSet.Builder b = ImmutableSet.builder(); - for (Map.Entry e : entrySet()) - b.add(e.getValue()); - return b.build(); + return new AbstractCollection<>() + { + @Override + public Iterator iterator() + { + return Iterators.transform(BTree.>iterator(tree), Entry::getValue); + } + + @Override + public int size() + { + return AbstractBTreeMap.this.size(); + } + }; } @Override