Skip to content

Commit 8991cfa

Browse files
committed
Check after each executed command if execution took too long already
1 parent 5bae370 commit 8991cfa

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/canvas.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ var CanvasGraphics = (function canvasGraphics() {
6464
// before it stops and shedules a continue of execution.
6565
var kExecutionTime = 50;
6666

67-
// Number of IR commands to execute before checking
68-
// if we execute longer then `kExecutionTime`.
69-
var kExecutionTimeCheck = 500;
70-
7167
function constructor(canvasCtx, objs) {
7268
this.ctx = canvasCtx;
7369
this.current = new CanvasExtraState();
@@ -112,31 +108,33 @@ var CanvasGraphics = (function canvasGraphics() {
112108
var i = executionStartIdx || 0;
113109
var argsArrayLen = argsArray.length;
114110

111+
// Sometimes the IRQueue to execute is empty.
112+
if (argsArrayLen == i) {
113+
return i;
114+
}
115+
115116
var executionEndIdx;
116117
var startTime = Date.now();
117118

118119
var objs = this.objs;
119120

120-
do {
121-
executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck);
122-
123-
for (i; i < executionEndIdx; i++) {
124-
if (fnArray[i] !== 'dependency') {
125-
this[fnArray[i]].apply(this, argsArray[i]);
126-
} else {
127-
var deps = argsArray[i];
128-
for (var n = 0, nn = deps.length; n < nn; n++) {
129-
var depObjId = deps[n];
130-
131-
// If the promise isn't resolved yet, add the continueCallback
132-
// to the promise and bail out.
133-
if (!objs.isResolved(depObjId)) {
134-
objs.get(depObjId, continueCallback);
135-
return i;
136-
}
121+
while (true) {
122+
if (fnArray[i] !== 'dependency') {
123+
this[fnArray[i]].apply(this, argsArray[i]);
124+
} else {
125+
var deps = argsArray[i];
126+
for (var n = 0, nn = deps.length; n < nn; n++) {
127+
var depObjId = deps[n];
128+
129+
// If the promise isn't resolved yet, add the continueCallback
130+
// to the promise and bail out.
131+
if (!objs.isResolved(depObjId)) {
132+
objs.get(depObjId, continueCallback);
133+
return i;
137134
}
138135
}
139136
}
137+
i++;
140138

141139
// If the entire IRQueue was executed, stop as were done.
142140
if (i == argsArrayLen) {
@@ -153,7 +151,7 @@ var CanvasGraphics = (function canvasGraphics() {
153151

154152
// If the IRQueue isn't executed completly yet OR the execution time
155153
// was short enough, do another execution round.
156-
} while (true);
154+
}
157155
},
158156

159157
endDrawing: function canvasGraphicsEndDrawing() {

0 commit comments

Comments
 (0)