diff options
author | Kim Alvefur <zash@zash.se> | 2017-12-03 15:03:25 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-12-03 15:03:25 +0100 |
commit | da570eb0a423c412d44ddc0855826037232d928f (patch) | |
tree | 39059da358fe92758d409757eacb62448fd420dc | |
parent | af554a9febee4bedfcfacd457a957e6a231dbd25 (diff) | |
download | prosody-da570eb0a423c412d44ddc0855826037232d928f.tar.gz prosody-da570eb0a423c412d44ddc0855826037232d928f.zip |
util.crand: Use a small buffer on the stack for small pieces of random, should be faster
-rw-r--r-- | util-src/crand.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/util-src/crand.c b/util-src/crand.c index d15fc090..ab2f4ad1 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -58,9 +58,19 @@ int getrandom(void *buf, size_t buflen, unsigned int flags) { #error util.crand compiled without a random source #endif +#ifndef SMALLBUFSIZ +#define SMALLBUFSIZ 32 +#endif + int Lrandom(lua_State *L) { + char smallbuf[SMALLBUFSIZ]; + char *buf = &smallbuf[0]; const size_t len = luaL_checkinteger(L, 1); - void *buf = lua_newuserdata(L, len); + + if(len > SMALLBUFSIZ) { + buf = lua_newuserdata(L, len); + } + #if defined(WITH_GETRANDOM) /* |