Browse Source

Micro optimization of ArithmeticDecoder_readBit

p01 11 years ago
parent
commit
bd9419f1ef
  1. 37
      src/core/arithmetic_decoder.js

37
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 cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
var qeTableIcx = QeTable[cx_index]; var qeTableIcx = QeTable[cx_index];
var qeIcx = qeTableIcx.qe; var qeIcx = qeTableIcx.qe;
var nmpsIcx = qeTableIcx.nmps;
var nlpsIcx = qeTableIcx.nlps;
var switchIcx = qeTableIcx.switchFlag;
var d; var d;
this.a -= qeIcx; var a = this.a - qeIcx;
if (this.chigh < qeIcx) { if (this.chigh < qeIcx) {
// exchangeLps // exchangeLps
if (this.a < qeIcx) { if (a < qeIcx) {
this.a = qeIcx; a = qeIcx;
d = cx_mps; d = cx_mps;
cx_index = nmpsIcx; cx_index = qeTableIcx.nmps;
} else { } else {
this.a = qeIcx; a = qeIcx;
d = 1 - cx_mps; d = 1 ^ cx_mps;
if (switchIcx) { if (qeTableIcx.switchFlag === 1) {
cx_mps = d; cx_mps = d;
} }
cx_index = nlpsIcx; cx_index = qeTableIcx.nlps;
} }
} else { } else {
this.chigh -= qeIcx; this.chigh -= qeIcx;
if ((this.a & 0x8000) !== 0) { if ((a & 0x8000) !== 0) {
this.a = a;
return cx_mps; return cx_mps;
} }
// exchangeMps // exchangeMps
if (this.a < qeIcx) { if (a < qeIcx) {
d = 1 - cx_mps; d = 1 ^ cx_mps;
if (switchIcx) { if (qeTableIcx.switchFlag === 1) {
cx_mps = d; cx_mps = d;
} }
cx_index = nlpsIcx; cx_index = qeTableIcx.nlps;
} else { } else {
d = cx_mps; d = cx_mps;
cx_index = nmpsIcx; cx_index = qeTableIcx.nmps;
} }
} }
// C.3.3 renormD; // C.3.3 renormD;
@ -171,11 +169,12 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
this.byteIn(); this.byteIn();
} }
this.a <<= 1; a <<= 1;
this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1); this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
this.clow = (this.clow << 1) & 0xFFFF; this.clow = (this.clow << 1) & 0xFFFF;
this.ct--; this.ct--;
} while ((this.a & 0x8000) === 0); } while ((a & 0x8000) === 0);
this.a = a;
contexts[pos] = cx_index << 1 | cx_mps; contexts[pos] = cx_index << 1 | cx_mps;
return d; return d;

Loading…
Cancel
Save