From e2a24e69ec2f980a7416bb683a36f91b567b6e9a Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 18 Jan 2015 10:20:12 +0100 Subject: [PATCH] Invert #if[n]def __EMSCRIPTEN__ logic, put more common case first --- src/libsodium/randombytes/randombytes.c | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libsodium/randombytes/randombytes.c b/src/libsodium/randombytes/randombytes.c index b74719b1..3fd8a11d 100644 --- a/src/libsodium/randombytes/randombytes.c +++ b/src/libsodium/randombytes/randombytes.c @@ -30,29 +30,33 @@ randombytes_set_implementation(randombytes_implementation *impl) const char * randombytes_implementation_name(void) { -#ifdef __EMSCRIPTEN__ - return "js"; -#else +#ifndef __EMSCRIPTEN__ return implementation->implementation_name(); +#else + return "js"; #endif } uint32_t randombytes_random(void) { -#ifdef __EMSCRIPTEN__ +#ifndef __EMSCRIPTEN__ + return implementation->random(); +#else return EM_ASM_INT_V({ return Module.getRandomValue(); }); -#else - return implementation->random(); #endif } void randombytes_stir(void) { -#ifdef __EMSCRIPTEN__ +#ifndef __EMSCRIPTEN__ + if (implementation != NULL && implementation->stir != NULL) { + implementation->stir(); + } +#else EM_ASM({ if (Module.getRandomValue === undefined) { try { @@ -78,10 +82,6 @@ randombytes_stir(void) } } }); -#else - if (implementation != NULL && implementation->stir != NULL) { - implementation->stir(); - } #endif } @@ -112,17 +112,17 @@ randombytes_uniform(const uint32_t upper_bound) void randombytes_buf(void * const buf, const size_t size) { -#ifdef __EMSCRIPTEN__ +#ifndef __EMSCRIPTEN__ + if (size > (size_t) 0U) { + implementation->buf(buf, size); + } +#else unsigned char *p = buf; size_t i; for (i = (size_t) 0U; i < size; i++) { p[i] = (unsigned char) randombytes_random(); } -#else - if (size > (size_t) 0U) { - implementation->buf(buf, size); - } #endif }