From cc0f7583b0bd61f6db346f450cd5b30d2cd6190f Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sun, 26 Nov 2017 14:53:56 +0300 Subject: [PATCH] Minor performance improvement --- .../org/teavm/classlib/impl/ServiceLoaderSupport.java | 4 ++-- .../java/org/teavm/jso/impl/JSDependencyListener.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java b/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java index 376b6b9b7..47063b316 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java @@ -40,7 +40,7 @@ import org.teavm.model.MethodReference; import org.teavm.model.ValueType; public class ServiceLoaderSupport extends AbstractDependencyListener implements Generator { - private Set achievedClasses = new HashSet<>(); + private Set reachedClasses = new HashSet<>(); private Map> serviceMap = new HashMap<>(); private DependencyNode allClassesNode; private ClassLoader classLoader; @@ -92,7 +92,7 @@ public class ServiceLoaderSupport extends AbstractDependencyListener implements @Override public void classReached(DependencyAgent agent, String className, CallLocation location) { - if (!achievedClasses.add(className)) { + if (!reachedClasses.add(className)) { return; } try { diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java index 6f292f60a..934cf865c 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java @@ -15,6 +15,7 @@ */ package org.teavm.jso.impl; +import java.util.HashSet; import java.util.Set; import org.teavm.dependency.AbstractDependencyListener; import org.teavm.dependency.DependencyAgent; @@ -27,6 +28,8 @@ import org.teavm.model.MethodReference; class JSDependencyListener extends AbstractDependencyListener { private JSBodyRepository repository; + private Set reachedClasses = new HashSet<>(); + private Set reachedMethods = new HashSet<>(); JSDependencyListener(JSBodyRepository repository) { this.repository = repository; @@ -35,6 +38,9 @@ class JSDependencyListener extends AbstractDependencyListener { @Override public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { MethodReference ref = method.getReference(); + if (!reachedMethods.add(ref)) { + return; + } Set callbackMethods = repository.callbackMethods.get(ref); if (callbackMethods != null) { for (MethodReference callbackMethod : callbackMethods) { @@ -45,6 +51,9 @@ class JSDependencyListener extends AbstractDependencyListener { @Override public void classReached(DependencyAgent agent, String className, CallLocation location) { + if (!reachedClasses.add(className)) { + return; + } ClassReader cls = agent.getClassSource().get(className); for (MethodReader method : cls.getMethods()) { AnnotationReader exposeAnnot = method.getAnnotations().get(JSMethodToExpose.class.getName());