Fixed goto emulation in inffast

This commit is contained in:
Vitaly Puzrin 2014-03-12 03:24:12 +04:00
parent aa281b06ed
commit b03bbe55a7

View file

@ -94,8 +94,6 @@ module.exports = function inflate_fast(strm, start) {
lmask = (1 << state.lenbits) - 1; lmask = (1 << state.lenbits) - 1;
dmask = (1 << state.distbits) - 1; dmask = (1 << state.distbits) - 1;
//goto flags
var _dolen, _dodist;
/* decode literals and length/distances until end-of-block or not enough /* decode literals and length/distances until end-of-block or not enough
input data or output space */ input data or output space */
@ -112,8 +110,7 @@ module.exports = function inflate_fast(strm, start) {
lcode.fill(hold & lmask, here); lcode.fill(hold & lmask, here);
dolen: dolen:
do { // Goto emulation for (;;) { // Goto emulation
_dolen = false;
op = here.bits; op = here.bits;
hold >>>= op; hold >>>= op;
bits -= op; bits -= op;
@ -146,8 +143,7 @@ module.exports = function inflate_fast(strm, start) {
dcode.fill(hold & dmask, here); dcode.fill(hold & dmask, here);
dodist: dodist:
do { // goto emulation for (;;) { // goto emulation
_dodist = false;
op = here.bits; op = here.bits;
hold >>>= op; hold >>>= op;
bits -= op; bits -= op;
@ -279,7 +275,6 @@ module.exports = function inflate_fast(strm, start) {
} }
else if ((op & 64) === 0) { /* 2nd level distance code */ else if ((op & 64) === 0) { /* 2nd level distance code */
dcode.fill(here.val + (hold & ((1 << op) - 1)), here); dcode.fill(here.val + (hold & ((1 << op) - 1)), here);
_dodist = true;
continue dodist; continue dodist;
} }
else { else {
@ -287,11 +282,12 @@ module.exports = function inflate_fast(strm, start) {
state.mode = BAD; state.mode = BAD;
break top; break top;
} }
} while (_dodist);
break; // need to emulate goto via "continue"
}
} }
else if ((op & 64) === 0) { /* 2nd level length code */ else if ((op & 64) === 0) { /* 2nd level length code */
lcode.fill(here.val + (hold & ((1 << op) - 1)), here); lcode.fill(here.val + (hold & ((1 << op) - 1)), here);
_dolen = true;
continue dolen; continue dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) { /* end-of-block */
@ -304,7 +300,9 @@ module.exports = function inflate_fast(strm, start) {
state.mode = BAD; state.mode = BAD;
break top; break top;
} }
} while (_dolen);
break; // need to emulate goto via "continue"
}
} while (_in < last && _out < end); } while (_in < last && _out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */