]> granicus.if.org Git - libevent/commitdiff
optimize by removing a variable
authorNiels Provos <provos@gmail.com>
Sun, 16 Sep 2007 02:26:37 +0000 (02:26 +0000)
committerNiels Provos <provos@gmail.com>
Sun, 16 Sep 2007 02:26:37 +0000 (02:26 +0000)
svn:r433

event_tagging.c

index 955b3a0cbaea1c1d903cdc9556068df5439f33fc..ddc281e1f5971111293f262aeb69c5c5d1a14906 100644 (file)
@@ -155,26 +155,25 @@ decode_int_internal(uint32_t *pnumber, struct evbuffer *evbuf, int dodrain)
        uint32_t number = 0;
        uint8_t *data = EVBUFFER_DATA(evbuf);
        int len = EVBUFFER_LENGTH(evbuf);
-       int nibbles = 0, off;
+       int nibbles = 0;
 
        if (!len)
                return (-1);
 
        nibbles = ((data[0] & 0xf0) >> 4) + 1;
-       if (nibbles > 8 || (nibbles >> 1) > len - 1)
+       if (nibbles > 8 || (nibbles >> 1) + 1 > len)
                return (-1);
+       len = (nibbles >> 1) + 1;
 
-       off = nibbles;
-       while (off > 0) {
+       while (nibbles > 0) {
                number <<= 4;
-               if (off & 0x1)
-                       number |= data[off >> 1] & 0x0f;
+               if (nibbles & 0x1)
+                       number |= data[nibbles >> 1] & 0x0f;
                else
-                       number |= (data[off >> 1] & 0xf0) >> 4;
-               off--;
+                       number |= (data[nibbles >> 1] & 0xf0) >> 4;
+               nibbles--;
        }
 
-       len = (nibbles >> 1) + 1;
        if (dodrain)
                evbuffer_drain(evbuf, len);