From bd9419f1efdb710cb1fa5955eeda1599f9568af4 Mon Sep 17 00:00:00 2001 From: p01 Date: Thu, 13 Mar 2014 15:09:33 +0100 Subject: [PATCH] Micro optimization of ArithmeticDecoder_readBit --- src/core/arithmetic_decoder.js | 37 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/core/arithmetic_decoder.js b/src/core/arithmetic_decoder.js index fae2edbe6f3f0..6d21cf63aaafe 100644 --- a/src/core/arithmetic_decoder.js +++ b/src/core/arithmetic_decoder.js @@ -128,41 +128,39 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() { var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1; var qeTableIcx = QeTable[cx_index]; var qeIcx = qeTableIcx.qe; - var nmpsIcx = qeTableIcx.nmps; - var nlpsIcx = qeTableIcx.nlps; - var switchIcx = qeTableIcx.switchFlag; var d; - this.a -= qeIcx; + var a = this.a - qeIcx; if (this.chigh < qeIcx) { // exchangeLps - if (this.a < qeIcx) { - this.a = qeIcx; + if (a < qeIcx) { + a = qeIcx; d = cx_mps; - cx_index = nmpsIcx; + cx_index = qeTableIcx.nmps; } else { - this.a = qeIcx; - d = 1 - cx_mps; - if (switchIcx) { + a = qeIcx; + d = 1 ^ cx_mps; + if (qeTableIcx.switchFlag === 1) { cx_mps = d; } - cx_index = nlpsIcx; + cx_index = qeTableIcx.nlps; } } else { this.chigh -= qeIcx; - if ((this.a & 0x8000) !== 0) { + if ((a & 0x8000) !== 0) { + this.a = a; return cx_mps; } // exchangeMps - if (this.a < qeIcx) { - d = 1 - cx_mps; - if (switchIcx) { + if (a < qeIcx) { + d = 1 ^ cx_mps; + if (qeTableIcx.switchFlag === 1) { cx_mps = d; } - cx_index = nlpsIcx; + cx_index = qeTableIcx.nlps; } else { d = cx_mps; - cx_index = nmpsIcx; + cx_index = qeTableIcx.nmps; } } // C.3.3 renormD; @@ -171,11 +169,12 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() { this.byteIn(); } - this.a <<= 1; + a <<= 1; this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1); this.clow = (this.clow << 1) & 0xFFFF; this.ct--; - } while ((this.a & 0x8000) === 0); + } while ((a & 0x8000) === 0); + this.a = a; contexts[pos] = cx_index << 1 | cx_mps; return d;