Minor performance improvement

This commit is contained in:
Alexey Andreev 2017-11-26 14:53:56 +03:00
parent 0ecafbe4b4
commit cc0f7583b0
2 changed files with 11 additions and 2 deletions

View File

@ -40,7 +40,7 @@ import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
public class ServiceLoaderSupport extends AbstractDependencyListener implements Generator {
private Set<String> achievedClasses = new HashSet<>();
private Set<String> reachedClasses = new HashSet<>();
private Map<String, List<String>> 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 {

View File

@ -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<String> reachedClasses = new HashSet<>();
private Set<MethodReference> 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<MethodReference> 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());