From: Alex Elder Date: Fri, 18 Feb 2011 21:21:01 +0000 (+0000) Subject: xfsprogs: metadump: replace repeated blocks with a loop X-Git-Tag: v3.1.5~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e444bd0c1aa590c4b7b841595fad1a37882b6902;p=thirdparty%2Fxfsprogs-dev.git xfsprogs: metadump: replace repeated blocks with a loop Each of the last five characters in the obfuscated name are generated the same way. Replace that repeated block of code with an equivalent loop. Signed-off-by: Alex Elder Reviewed-by: Dave Chinner --- diff --git a/db/metadump.c b/db/metadump.c index b8d259b2c..5d04201fd 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -511,41 +511,16 @@ generate_obfuscated_name( newhash = rol32(newhash, 3) ^ hash; high_bit = 0; - - newp[namelen - 5] = ((newhash >> 28) & 0x7f) ^ high_bit; - if (is_invalid_char(newp[namelen - 5])) { - newp[namelen - 5] ^= 1; - high_bit = 0x80; - } else - high_bit = 0; - - newp[namelen - 4] = ((newhash >> 21) & 0x7f) ^ high_bit; - if (is_invalid_char(newp[namelen - 4])) { - newp[namelen - 4] ^= 1; - high_bit = 0x80; - } else - high_bit = 0; - - newp[namelen - 3] = ((newhash >> 14) & 0x7f) ^ high_bit; - if (is_invalid_char(newp[namelen - 3])) { - newp[namelen - 3] ^= 1; - high_bit = 0x80; - } else - high_bit = 0; - - newp[namelen - 2] = ((newhash >> 7) & 0x7f) ^ high_bit; - if (is_invalid_char(newp[namelen - 2])) { - newp[namelen - 2] ^= 1; - high_bit = 0x80; - } else - high_bit = 0; - - newp[namelen - 1] = ((newhash >> 0) & 0x7f) ^ high_bit; - if (is_invalid_char(newp[namelen - 1])) { - newp[namelen - 1] ^= 1; - high_bit = 0x80; - } else - high_bit = 0; + for (i = 5; i > 0; i--) { + int shift = (i - 1) * 7; + + newp[namelen - i] = ((newhash >> shift) & 0x7f) ^ high_bit; + if (is_invalid_char(newp[namelen - i])) { + newp[namelen - i] ^= 1; + high_bit = 0x80; + } else + high_bit = 0; + } /* * If we flipped a bit on the last byte, we need to