This is an automated email from the ASF dual-hosted git repository.
neilcsmith pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/delivery by this push:
new 1a98d8eb18 #4500 static imported methods slow down auto completion
new ceffbbc8c1 Merge pull request #4502 from mbien/fast-star-import
1a98d8eb18 is described below
commit 1a98d8eb188a1bc43ce8044317d70559251cef9b
Author: Michael Bien <[email protected]>
AuthorDate: Sat Aug 13 15:53:54 2022 +0200
#4500 static imported methods slow down auto completion
- conflictsWithLocal is called in a loop and recomputes methodsIn
on each iteration which scales very badly (quadratic complexity)
- we can simply extract this part out of the loop
- see #4500 for graphs, benchmark and more detail
---
.../modules/java/completion/JavaCompletionTask.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git
a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
index f88ae040ad..9224475bbc 100644
---
a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
+++
b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
@@ -3380,6 +3380,8 @@ public final class JavaCompletionTask<T> extends BaseTask
{
addAllStaticMemberNames(env);
}
final TypeElement enclClass = scope.getEnclosingClass();
+ List<ExecutableElement> methodsIn = null;
+
for (Element e : locals) {
switch (simplifyElementKind(e.getKind())) {
case ENUM_CONSTANT:
@@ -3399,8 +3401,11 @@ public final class JavaCompletionTask<T> extends
BaseTask {
}
break;
case METHOD:
+ if (methodsIn == null) {
+ methodsIn = ElementFilter.methodsIn(locals);
+ }
ExecutableType et = (ExecutableType) asMemberOf(e,
enclClass != null ? enclClass.asType() : null, types);
- if (e.getEnclosingElement() != enclClass &&
conflictsWithLocal(e.getSimpleName(), enclClass, locals)) {
+ if (e.getEnclosingElement() != enclClass &&
conflictsWithLocalMethods(e.getSimpleName(), enclClass, methodsIn)) {
results.add(itemFactory.createStaticMemberItem(env.getController(),
(DeclaredType)e.getEnclosingElement().asType(), e, et, false, anchorOffset,
elements.isDeprecated(e), env.addSemicolon()));
} else {
results.add(itemFactory.createExecutableItem(env.getController(),
(ExecutableElement) e, et, anchorOffset, null,
env.getScope().getEnclosingClass() != e.getEnclosingElement(),
elements.isDeprecated(e), false, env.addSemicolon(), isOfSmartType(env,
getCorrectedReturnType(env, et, (ExecutableElement) e, enclClass != null ?
enclClass.asType() : null), smartTypes), env.assignToVarPos(), false));
@@ -6216,9 +6221,9 @@ public final class JavaCompletionTask<T> extends BaseTask
{
}
return false;
}
-
- private boolean conflictsWithLocal(Name name, TypeElement enclClass,
Iterable<? extends Element> locals) {
- for (ExecutableElement local : ElementFilter.methodsIn(locals)) {
+
+ private static boolean conflictsWithLocalMethods(Name name, TypeElement
enclClass, List<ExecutableElement> methodsIn) {
+ for (ExecutableElement local : methodsIn) {
if (local.getEnclosingElement() == enclClass &&
name.contentEquals(local.getSimpleName())) {
return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists