Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a totalLength getter to OperatorList, since the length is zero after flushing #6566

Merged
merged 1 commit into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ var OperatorList = (function OperatorListClosure() {
this.fnArray = [];
this.argsArray = [];
this.dependencies = {};
this._totalLength = 0;
this.pageIndex = pageIndex;
this.intent = intent;
}
Expand All @@ -1929,6 +1930,14 @@ var OperatorList = (function OperatorListClosure() {
return this.argsArray.length;
},

/**
* @returns {number} The total length of the entire operator list,
* since `this.length === 0` after flushing.
*/
get totalLength() {
return (this._totalLength + this.length);
},

addOp: function(fn, args) {
this.fnArray.push(fn);
this.argsArray.push(args);
Expand Down Expand Up @@ -1977,12 +1986,15 @@ var OperatorList = (function OperatorListClosure() {
new QueueOptimizer().optimize(this);
}
var transfers = getTransfers(this);
var length = this.length;
this._totalLength += length;

this.messageHandler.send('RenderPageChunk', {
operatorList: {
fnArray: this.fnArray,
argsArray: this.argsArray,
lastChunk: lastChunk,
length: this.length
length: length
},
pageIndex: this.pageIndex,
intent: this.intent
Expand Down
2 changes: 1 addition & 1 deletion src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
finishWorkerTask(task);

info('page=' + pageNum + ' - getOperatorList: time=' +
(Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
(Date.now() - start) + 'ms, len=' + operatorList.totalLength);
}, function(e) {
finishWorkerTask(task);
if (task.terminated) {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/evaluator_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,25 @@ describe('evaluator', function() {
});
});
});

describe('operator list', function () {
function MessageHandlerMock() { }
MessageHandlerMock.prototype = {
send: function () { },
};

it('should get correct total length after flushing', function () {
var operatorList = new OperatorList(null, new MessageHandlerMock());
operatorList.addOp(OPS.save, null);
operatorList.addOp(OPS.restore, null);

expect(operatorList.totalLength).toEqual(2);
expect(operatorList.length).toEqual(2);

operatorList.flush();

expect(operatorList.totalLength).toEqual(2);
expect(operatorList.length).toEqual(0);
});
});
});