]> granicus.if.org Git - php/commitdiff
Avoid conditions inside loop
authorAnatol Belski <ab@php.net>
Fri, 9 Feb 2018 16:47:03 +0000 (17:47 +0100)
committerAnatol Belski <ab@php.net>
Fri, 9 Feb 2018 18:28:20 +0000 (19:28 +0100)
ext/hash/hash_fnv.c

index 8736f94b8416b983a724c0653d95fcd2c5ad4e29..72ef2ee8ca9ab88240857c1b14a9bec5519c017d 100644 (file)
@@ -160,15 +160,16 @@ fnv_32_buf(void *buf, size_t len, uint32_t hval, int alternate)
        /*
         * FNV-1 hash each octet in the buffer
         */
-       while (bp < be) {
-
-               if (alternate == 0) {
+       if (alternate == 0) {
+               while (bp < be) {
                        /* multiply by the 32 bit FNV magic prime mod 2^32 */
                        hval *= PHP_FNV_32_PRIME;
 
                        /* xor the bottom with the current octet */
                        hval ^= (uint32_t)*bp++;
-               } else {
+               }
+       } else {
+               while (bp < be) {
                        /* xor the bottom with the current octet */
                        hval ^= (uint32_t)*bp++;
 
@@ -202,15 +203,17 @@ fnv_64_buf(void *buf, size_t len, uint64_t hval, int alternate)
        /*
         * FNV-1 hash each octet of the buffer
         */
-       while (bp < be) {
 
-               if (alternate == 0) {
+       if (alternate == 0) {
+               while (bp < be) {
                        /* multiply by the 64 bit FNV magic prime mod 2^64 */
                        hval *= PHP_FNV_64_PRIME;
 
                        /* xor the bottom with the current octet */
                        hval ^= (uint64_t)*bp++;
-                } else {
+               }
+        } else {
+               while (bp < be) {
                        /* xor the bottom with the current octet */
                        hval ^= (uint64_t)*bp++;