You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/05 14:52:30 UTC
[groovy] branch master updated: Trivial tweak for hash table of
hash-joins
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 00fc7a4 Trivial tweak for hash table of hash-joins
00fc7a4 is described below
commit 00fc7a438c28080799efc4c0c71779307606f4fb
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 5 22:52:10 2021 +0800
Trivial tweak for hash table of hash-joins
---
.../collection/runtime/QueryableCollection.java | 29 ++++++++++++++--------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
index 7438166..e2f3398 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
@@ -129,21 +129,30 @@ class QueryableCollection<T> implements Queryable<T>, Serializable {
return from(stream);
}
+ private static final class Bucket<E> extends ArrayList<E> {
+ private static final long serialVersionUID = 2813676753531316403L;
+ Bucket() {
+ this(HASHTABLE_BUCKET_INITIAL_SIZE);
+ }
+ Bucket(int initialCapacity) {
+ super(initialCapacity);
+ }
+ static <E> Bucket<E> singletonBucket(E o) {
+ Bucket<E> bucket = new Bucket<>();
+ bucket.add(o);
+ return bucket;
+ }
+ }
+
private static <U> Supplier<Map<Integer, List<U>>> createHashTableSupplier(Queryable<? extends U> queryable, Function<? super U, ?> fieldsExtractor2) {
return () -> queryable.stream()
.collect(
Collectors.toMap(
c -> hash(fieldsExtractor2.apply(c)),
- Collections::singletonList,
- (oldList, newList) -> {
- if (!(oldList instanceof ArrayList)) {
- List<U> tmpList = new ArrayList<>(HASHTABLE_BUCKET_INITIAL_SIZE);
- tmpList.addAll(oldList);
- oldList = tmpList;
- }
-
- oldList.addAll(newList);
- return oldList;
+ Bucket::singletonBucket,
+ (oldBucket, newBucket) -> {
+ oldBucket.addAll(newBucket);
+ return oldBucket;
}
));
}