• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 271

29 Sep 2025 12:12PM UTC coverage: 64.649% (+2.4%) from 62.222%
271

Pull #1096

circleci

Frotty
Merge branch 'perf-improvements' of https://github.com/wurstscript/WurstScript into perf-improvements
Pull Request #1096: Perf improvements

18202 of 28155 relevant lines covered (64.65%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/validation/controlflow/ForwardExecution.java
1
package de.peeeq.wurstscript.validation.controlflow;
2

3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import de.peeeq.wurstscript.ast.AstElementWithBody;
6
import de.peeeq.wurstscript.ast.WStatement;
7

8
import java.util.*;
9

10
public class ForwardExecution<T, Target extends AstElementWithBody> {
11

12
    private final ForwardMethod<T, Target> method;
13
    private final Map<WStatement, T> currentValues = Maps.newLinkedHashMap();
×
14
    private final AstElementWithBody f;
15

16
    private final PriorityQueue<WStatement> todo = new PriorityQueue<>(11, (o1, o2) -> o2.getSource().getLeftPos() - o1.getSource().getLeftPos());
×
17

18
    ForwardExecution(Target f, ForwardMethod<T, Target> method) {
×
19
        this.f = f;
×
20
        this.method = method;
×
21
        method.setFuncDef(f);
×
22
    }
×
23

24

25
    void execute() {
26
        if (f.getBody().isEmpty()) {
×
27
            throw new Error("" + f);
×
28
        }
29
        addTodo(f.getBody().get(0));
×
30
        while (!todo.isEmpty()) {
×
31
            checkStmt(fromTodo());
×
32
        }
33
        method.checkFinal(get(f.getBody().get(f.getBody().size() - 1)));
×
34
    }
×
35

36

37
    private WStatement fromTodo() {
38
        return todo.poll();
×
39
    }
40

41
    private void addTodo(WStatement s) {
42
        if (todo.contains(s)) {
×
43
            return;
×
44
        }
45
        todo.add(s);
×
46
    }
×
47

48
    private void checkStmt(WStatement s) {
49
//                debug("statement " +Utils.printElement(s) +"  in line " + s.attrSource().getLine());
50
        T incoming = method.merge(get(s.attrPreviousStatements()));
×
51
        T oldR = currentValues.get(s);
×
52
        T r = method.calculate(s, incoming);
×
53
//                debug("        from " + method.print(oldR) + " to " + method.print(r));
54
        if (oldR == null || !method.equality(oldR, r)) {
×
55
            // value changed...
56
            currentValues.put(s, r);
×
57
            // pass changes to following statements
58
            for (WStatement next : s.attrNextStatements()) {
×
59
                addTodo(next);
×
60
            }
×
61
        }
62
    }
×
63

64
    private Collection<T> get(List<WStatement> previousStatements) {
65
        if (previousStatements.isEmpty()) {
×
66
            return Collections.singleton(method.startValue());
×
67
        }
68
        Collection<T> result = Lists.newArrayList();
×
69
        for (WStatement s : previousStatements) {
×
70
//                        debug("        prev: " + Utils.printElement(s) +"  in line " + s.attrSource().getLine()
71
//                                        + " " + method.print(currentValues.get(s)));
72
            result.add(get(s));
×
73
        }
×
74
        return result;
×
75
    }
76

77
//        private void debug(String msg) {
78
//                if (method.debug) {
79
//                        WLogger.info(msg);
80
//                }
81
//        }
82

83

84
    private T get(WStatement s) {
85
        T t = currentValues.get(s);
×
86
        if (t == null) {
×
87
            t = method.startValue();
×
88
        }
89
        return t;
×
90
    }
91

92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc