Skip to content

Commit 3758e39

Browse files
author
emmanue1
committed
Limit the excessive time taken by layout
1 parent 6ecf551 commit 3758e39

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/jd/core/v1/service/layouter/LayoutFragmentProcessor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public void process(Message message) throws Exception {
5555
UpdateSpacerBetweenMovableBlocksVisitor visitor = new UpdateSpacerBetweenMovableBlocksVisitor();
5656

5757
// Try to release constraints twice for each section
58+
int sumOfRates = Integer.MAX_VALUE;
5859
int max = sections.size() * 2;
5960

61+
if (max > 20) {
62+
max = 20;
63+
}
64+
6065
for (int loop=0; loop<max; loop++) {
6166
// Update spacers
6267
visitor.reset();
@@ -84,6 +89,7 @@ public void process(Message message) throws Exception {
8489
}
8590

8691
// Update the ratings
92+
int newSumOfRates = 0;
8793
Section mostConstrainedSection = sections.get(0);
8894

8995
for (Section section : sections) {
@@ -92,6 +98,8 @@ public void process(Message message) throws Exception {
9298
if (mostConstrainedSection.getRate() < section.getRate()) {
9399
mostConstrainedSection = section;
94100
}
101+
102+
newSumOfRates += section.getRate();
95103
}
96104

97105
// Move fragments from the most constrained section
@@ -100,6 +108,13 @@ public void process(Message message) throws Exception {
100108
break;
101109
}
102110

111+
if (sumOfRates > newSumOfRates) {
112+
sumOfRates = newSumOfRates;
113+
} else {
114+
// The sum of the constraints does not decrease -> Quit loop
115+
break;
116+
}
117+
103118
if (! mostConstrainedSection.releaseConstraints(holder)) {
104119
break;
105120
}

0 commit comments

Comments
 (0)