mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Minor performance improvement
This commit is contained in:
parent
a9d47b5ce7
commit
f4c5b5073a
|
@ -18,6 +18,7 @@ package org.teavm.dependency;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -67,7 +68,7 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
private CachedMapper<String, ClassDependency> classCache;
|
private CachedMapper<String, ClassDependency> classCache;
|
||||||
private List<DependencyListener> listeners = new ArrayList<>();
|
private List<DependencyListener> listeners = new ArrayList<>();
|
||||||
private ServiceRepository services;
|
private ServiceRepository services;
|
||||||
private Queue<Runnable> tasks = new ArrayDeque<>();
|
private Deque<Runnable> tasks = new ArrayDeque<>();
|
||||||
private Queue<Runnable> deferredTasks = new ArrayDeque<>();
|
private Queue<Runnable> deferredTasks = new ArrayDeque<>();
|
||||||
List<DependencyType> types = new ArrayList<>();
|
List<DependencyType> types = new ArrayList<>();
|
||||||
private Map<String, DependencyType> typeMap = new HashMap<>();
|
private Map<String, DependencyType> typeMap = new HashMap<>();
|
||||||
|
@ -245,7 +246,35 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void schedulePropagation(DependencyNodeToNodeTransition consumer, DependencyType[] types) {
|
||||||
|
if (types.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (types.length == 1) {
|
||||||
|
schedulePropagation(consumer, types[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propagationDepth < 50) {
|
||||||
|
++propagationDepth;
|
||||||
|
consumer.consume(types);
|
||||||
|
--propagationDepth;
|
||||||
|
} else {
|
||||||
|
tasks.add(() -> {
|
||||||
|
consumer.consume(types);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void schedulePropagation(DependencyConsumer consumer, DependencyType[] types) {
|
void schedulePropagation(DependencyConsumer consumer, DependencyType[] types) {
|
||||||
|
if (types.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (types.length == 1) {
|
||||||
|
schedulePropagation(consumer, types[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (propagationDepth < 50) {
|
if (propagationDepth < 50) {
|
||||||
++propagationDepth;
|
++propagationDepth;
|
||||||
for (DependencyType type : types) {
|
for (DependencyType type : types) {
|
||||||
|
@ -511,7 +540,7 @@ public class DependencyChecker implements DependencyInfo {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (!tasks.isEmpty()) {
|
while (!tasks.isEmpty()) {
|
||||||
tasks.poll().run();
|
tasks.removeLast().run();
|
||||||
if (++index == 100) {
|
if (++index == 100) {
|
||||||
if (interruptor != null && !interruptor.shouldContinue()) {
|
if (interruptor != null && !interruptor.shouldContinue()) {
|
||||||
interrupted = true;
|
interrupted = true;
|
||||||
|
|
|
@ -72,7 +72,6 @@ class DependencyClassSource implements ClassHolderSource {
|
||||||
for (ClassHolderTransformer transformer : transformers) {
|
for (ClassHolderTransformer transformer : transformers) {
|
||||||
transformer.transformClass(cls, innerSource, diagnostics);
|
transformer.transformClass(cls, innerSource, diagnostics);
|
||||||
}
|
}
|
||||||
cls = ModelUtils.copyClass(cls);
|
|
||||||
}
|
}
|
||||||
return cls;
|
return cls;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.dependency;
|
package org.teavm.dependency;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
class DependencyNodeToNodeTransition implements DependencyConsumer {
|
class DependencyNodeToNodeTransition implements DependencyConsumer {
|
||||||
private DependencyNode source;
|
private DependencyNode source;
|
||||||
DependencyNode destination;
|
DependencyNode destination;
|
||||||
|
@ -43,4 +45,35 @@ class DependencyNodeToNodeTransition implements DependencyConsumer {
|
||||||
destination.propagate(type);
|
destination.propagate(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void consume(DependencyType[] types) {
|
||||||
|
DependencyType[] filtered = new DependencyType[types.length];
|
||||||
|
int j = 0;
|
||||||
|
for (DependencyType type : types) {
|
||||||
|
if (type.getName().startsWith("[")) {
|
||||||
|
source.getArrayItem().connect(destination.getArrayItem());
|
||||||
|
destination.getArrayItem().connect(source.getArrayItem());
|
||||||
|
}
|
||||||
|
if (type.getName().equals("java.lang.Class")) {
|
||||||
|
source.getClassValueNode().connect(destination.getClassValueNode());
|
||||||
|
}
|
||||||
|
if ((filter == null || filter.match(type)) && !destination.hasType(type)) {
|
||||||
|
filtered[j++] = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j == 1) {
|
||||||
|
destination.propagate(filtered[0]);
|
||||||
|
} else {
|
||||||
|
if (j < filtered.length) {
|
||||||
|
filtered = Arrays.copyOf(filtered, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
destination.propagate(filtered);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user