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/01/29 22:31:32 UTC
[groovy] branch GROOVY-9921 updated (20cc668 -> 9f63675)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch GROOVY-9921
in repository https://gitbox.apache.org/repos/asf/groovy.git.
discard 20cc668 GROOVY-9921: Replace legacy data structure with Java collection(SingleKeyHashMap)
new 9f63675 GROOVY-9921: Replace legacy data structure with Java collection(SingleKeyHashMap)
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (20cc668)
\
N -- N -- N refs/heads/GROOVY-9921 (9f63675)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[groovy] 01/01: GROOVY-9921: Replace legacy data structure with
Java collection(SingleKeyHashMap)
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9921
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 9f63675fa132a6776df7a25b9230c9861f9d2c36
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jan 30 00:54:34 2021 +0800
GROOVY-9921: Replace legacy data structure with Java collection(SingleKeyHashMap)
---
src/main/java/groovy/lang/MetaClassImpl.java | 21 ++++++---------------
.../groovy/runtime/metaclass/MetaMethodIndex.java | 18 ++++++------------
2 files changed, 12 insertions(+), 27 deletions(-)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index cdf6865..67f9e15 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -3858,21 +3858,12 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
private abstract class MethodIndexAction {
public void iterate() {
- final ComplexKeyHashMap.Entry[] table = metaMethodIndex.methodHeaders.getTable();
- int len = table.length;
- for (int i = 0; i != len; ++i) {
- for (SingleKeyHashMap.Entry classEntry = (SingleKeyHashMap.Entry) table[i];
- classEntry != null;
- classEntry = (SingleKeyHashMap.Entry) classEntry.next) {
-
- Class clazz = (Class) classEntry.getKey();
-
- if (skipClass(clazz)) continue;
-
- MetaMethodIndex.Header header = (MetaMethodIndex.Header) classEntry.getValue();
- for (MetaMethodIndex.Entry nameEntry = header.head; nameEntry != null; nameEntry = nameEntry.nextClassEntry) {
- methodNameAction(clazz, nameEntry);
- }
+ for (Map.Entry<Class, MetaMethodIndex.Header> classEntry : metaMethodIndex.methodHeaders.entrySet()) {
+ Class clazz = classEntry.getKey();
+ if (skipClass(clazz)) continue;
+ MetaMethodIndex.Header header = classEntry.getValue();
+ for (MetaMethodIndex.Entry nameEntry = header.head; nameEntry != null; nameEntry = nameEntry.nextClassEntry) {
+ methodNameAction(clazz, nameEntry);
}
}
}
diff --git a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java
index 5720f53..c1a86bf 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java
@@ -22,14 +22,15 @@ import groovy.lang.MetaMethod;
import org.codehaus.groovy.reflection.CachedClass;
import org.codehaus.groovy.reflection.GeneratedMetaMethod;
import org.codehaus.groovy.util.FastArray;
-import org.codehaus.groovy.util.SingleKeyHashMap;
import java.util.Arrays;
+import java.util.IdentityHashMap;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
public class MetaMethodIndex {
- public SingleKeyHashMap methodHeaders = new SingleKeyHashMap();
+ public final Map<Class, Header> methodHeaders = new IdentityHashMap<>();
public static class Header {
public Entry head;
@@ -85,13 +86,11 @@ public class MetaMethodIndex {
CachedClass last = null;
if (!theCachedClass.isInterface()) {
for (CachedClass c = theCachedClass; c != null; c = c.getCachedSuperClass()) {
- final SingleKeyHashMap.Entry e = methodHeaders.getOrPut(c.getTheClass());
- e.value = new Header(c.getTheClass(), last == null ? null : last.getTheClass());
+ methodHeaders.put(c.getTheClass(), new Header(c.getTheClass(), last == null ? null : last.getTheClass()));
last = c;
}
} else {
- final SingleKeyHashMap.Entry e = methodHeaders.getOrPut(Object.class);
- e.value = new Header(Object.class, theCachedClass.getTheClass());
+ methodHeaders.put(Object.class, new Header(Object.class, theCachedClass.getTheClass()));
}
}
@@ -237,12 +236,7 @@ public class MetaMethodIndex {
}
public Header getHeader(final Class cls) {
- SingleKeyHashMap.Entry head = methodHeaders.getOrPut(cls);
- if (head.value == null) {
- head.value = new Header(cls);
- }
- Header header = (Header) head.value;
- return header;
+ return methodHeaders.computeIfAbsent(cls, k -> new Header(cls));
}
public void copyNonPrivateMethods(final Class from, final Class to) {