[3.0] ab7a91e Use scalbn(3) rather than exp2(3), it should be faster and more portable.
Tollef Fog Heen
tfheen at varnish-cache.org
Mon Apr 16 10:20:35 CEST 2012
commit ab7a91edd8d8cd8eb040f2bde5ce4b336bada906
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 1 09:41:00 2011 +0000
Use scalbn(3) rather than exp2(3), it should be faster and more portable.
Fixes #1046
diff --git a/bin/varnishd/cache_dir_random.c b/bin/varnishd/cache_dir_random.c
index c2b74dd..27f120f 100644
--- a/bin/varnishd/cache_dir_random.c
+++ b/bin/varnishd/cache_dir_random.c
@@ -97,7 +97,7 @@ vdi_random_sha(const char *input, ssize_t len)
SHA256_Init(&ctx);
SHA256_Update(&ctx, input, len);
SHA256_Final(sign, &ctx);
- return (vle32dec(sign) / exp2(32));
+ return (scalbn(vle32dec(sign), -32));
}
/*
@@ -119,11 +119,11 @@ vdi_random_init_seed(const struct vdi_random *vs, const struct sess *sp)
break;
case c_hash:
AN(sp->digest);
- retval = vle32dec(sp->digest) / exp2(32);
+ retval = scalbn(vle32dec(sp->digest), -32);
break;
case c_random:
default:
- retval = random() / exp2(31);
+ retval = scalbn(random(), -31);
break;
}
return (retval);
More information about the varnish-commit
mailing list