golomb: Simplify get_ur_golomb_jpegls

Message ID 20170411102227.90157-1-lu_zero@gentoo.org
State New
Headers show

Commit Message

Luca Barbato April 11, 2017, 10:22 a.m.
The loop always consume the bit read and the new bitstream reader
can read 0 bits just fine.
---
 libavcodec/golomb.h | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Diego Biurrun April 11, 2017, 2:49 p.m. | #1
On Tue, Apr 11, 2017 at 12:22:27PM +0200, Luca Barbato wrote:
> The loop always consume the bit read and the new bitstream reader
> can read 0 bits just fine.

consume_S

> --- a/libavcodec/golomb.h
> +++ b/libavcodec/golomb.h
> @@ -290,16 +290,10 @@ static inline int get_ur_golomb_jpegls(BitstreamContext *bc, int k, int limit,
>          return buf;
>      } else {
>          int i;
> -        for (i = 0; i < limit && bitstream_peek(bc, 1) == 0 && bitstream_bits_left(bc) > 0; i++)
> -            bitstream_skip(bc, 1);
> -        bitstream_skip(bc, 1);
> +        for (i = 0; i < limit && bitstream_read_bit(bc) == 0 && bitstream_bits_left(bc) > 0; i++);

Move the semicolon to the next line for readability.

LGTM

Diego
Luca Barbato April 11, 2017, 3:32 p.m. | #2
On 11/04/2017 16:49, Diego Biurrun wrote:
> Move the semicolon to the next line for readability.

I was thinking about making that 3 lines to make it more evident

for (i = 0;
     i < limit && bitstream_read_bit(bc) == 0 && bitstream_bits_left(bc)
> 0;
     i++);
Diego Biurrun April 11, 2017, 3:41 p.m. | #3
On Tue, Apr 11, 2017 at 05:32:18PM +0200, Luca Barbato wrote:
> On 11/04/2017 16:49, Diego Biurrun wrote:
> > Move the semicolon to the next line for readability.
> 
> I was thinking about making that 3 lines to make it more evident
> 
> for (i = 0;
>      i < limit && bitstream_read_bit(bc) == 0 && bitstream_bits_left(bc)
> > 0;
>      i++);

Not necessary IMO.

Diego
Luca Barbato April 12, 2017, 1:27 p.m. | #4
On 11/04/2017 17:41, Diego Biurrun wrote:
> Not necessary IMO.

the line is extra long so with just the ; you get something quite weird
looking at 80 cols.

Patch

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 648f924..1977502 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -290,16 +290,10 @@  static inline int get_ur_golomb_jpegls(BitstreamContext *bc, int k, int limit,
         return buf;
     } else {
         int i;
-        for (i = 0; i < limit && bitstream_peek(bc, 1) == 0 && bitstream_bits_left(bc) > 0; i++)
-            bitstream_skip(bc, 1);
-        bitstream_skip(bc, 1);
+        for (i = 0; i < limit && bitstream_read_bit(bc) == 0 && bitstream_bits_left(bc) > 0; i++);
 
         if (i < limit - 1) {
-            if (k) {
-                buf = bitstream_read(bc, k);
-            } else {
-                buf = 0;
-            }
+            buf = bitstream_read(bc, k);
 
             return buf + (i << k);
         } else if (i == limit - 1) {