1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

vble: move get_bits_left() check out of inner loop, we can perform the check completely before the loop.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2011-11-12 02:02:22 +01:00
parent e3618cd4a8
commit dde0af2df1

View File

@@ -41,6 +41,7 @@ typedef struct {
static int vble_unpack(VBLEContext *ctx, GetBitContext *gb) static int vble_unpack(VBLEContext *ctx, GetBitContext *gb)
{ {
int i; int i;
int allbits = 0;
static const uint8_t LUT[256] = { static const uint8_t LUT[256] = {
8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, 8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
@@ -68,16 +69,17 @@ static int vble_unpack(VBLEContext *ctx, GetBitContext *gb)
return -1; return -1;
ctx->len[i] = 8; ctx->len[i] = 8;
} }
allbits += ctx->len[i];
} }
/* Check we have enough bits left */
if (get_bits_left(gb) < allbits)
return -1;
/* For any values that have length 0 */ /* For any values that have length 0 */
memset(ctx->val, 0, ctx->size); memset(ctx->val, 0, ctx->size);
for (i = 0; i < ctx->size; i++) { for (i = 0; i < ctx->size; i++) {
/* Check we have enough bits left */
if (get_bits_left(gb) < ctx->len[i])
return -1;
/* get_bits can't take a length of 0 */ /* get_bits can't take a length of 0 */
if (ctx->len[i]) if (ctx->len[i])
ctx->val[i] = (1 << ctx->len[i]) + get_bits(gb, ctx->len[i]) - 1; ctx->val[i] = (1 << ctx->len[i]) + get_bits(gb, ctx->len[i]) - 1;