Browse code

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>

Michael Niedermayer authored on 2011/11/12 10:02:22
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@ typedef struct {
41 41
 static int vble_unpack(VBLEContext *ctx, GetBitContext *gb)
42 42
 {
43 43
     int i;
44
+    int allbits = 0;
44 45
     static const uint8_t LUT[256] = {
45 46
         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,
46 47
         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)
68 68
                 return -1;
69 69
             ctx->len[i] = 8;
70 70
         }
71
+        allbits += ctx->len[i];
71 72
     }
72 73
 
74
+    /* Check we have enough bits left */
75
+    if (get_bits_left(gb) < allbits)
76
+        return -1;
77
+
73 78
     /* For any values that have length 0 */
74 79
     memset(ctx->val, 0, ctx->size);
75 80
 
76 81
     for (i = 0; i < ctx->size; i++) {
77
-        /* Check we have enough bits left */
78
-        if (get_bits_left(gb) < ctx->len[i])
79
-            return -1;
80
-
81 82
         /* get_bits can't take a length of 0 */
82 83
         if (ctx->len[i])
83 84
             ctx->val[i] = (1 << ctx->len[i]) + get_bits(gb, ctx->len[i]) - 1;