[Pkg-javascript-commits] [pdf.js] 95/174: Add a `totalLength` getter to `OperatorList`, since the `length` is zero after flushing

David Prévot taffit at moszumanska.debian.org
Thu Nov 19 18:45:22 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 1c66d4a106ab0e63ef48419c4d3a22c7314a3a80
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Mon Oct 26 16:38:06 2015 +0100

    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 41f6571..09417e0 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 7440534..72caafc 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 5e21122..c4543c4 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);
+    });
+  });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list