From 1c66d4a106ab0e63ef48419c4d3a22c7314a3a80 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 26 Oct 2015 16:38:06 +0100 Subject: [PATCH] Add a `totalLength` getter to `OperatorList`, since the `length` is zero after flushing In the `RenderPageRequest` handler in `worker.js`, we attempt to print an `info` message containing the rendering time and the length of the operator list. The latter is currently broken (and has been for quite some time), since the `length` of an `OperatorList` is reset when flushing occurs. This patch attempts to rectify this, by adding a getter which keeps track of the total length. --- src/core/evaluator.js | 14 +++++++++++++- src/core/worker.js | 2 +- test/unit/evaluator_spec.js | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 41f6571a7..09417e0ee 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -1920,6 +1920,7 @@ var OperatorList = (function OperatorListClosure() { this.fnArray = []; this.argsArray = []; this.dependencies = {}; + this._totalLength = 0; this.pageIndex = pageIndex; this.intent = intent; } @@ -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); @@ -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 diff --git a/src/core/worker.js b/src/core/worker.js index 7440534e7..72caafc7f 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -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) { diff --git a/test/unit/evaluator_spec.js b/test/unit/evaluator_spec.js index 5e21122c5..c4543c407 100644 --- a/test/unit/evaluator_spec.js +++ b/test/unit/evaluator_spec.js @@ -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); + }); + }); });