From d3cb224eb3074c6f467f135c6554b1a0b14e835e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 9 Feb 2018 17:47:03 +0100 Subject: [PATCH] Avoid conditions inside loop --- ext/hash/hash_fnv.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/hash/hash_fnv.c b/ext/hash/hash_fnv.c index 8736f94b84..72ef2ee8ca 100644 --- a/ext/hash/hash_fnv.c +++ b/ext/hash/hash_fnv.c @@ -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++; -- 2.50.1