Software /
code /
prosody
Changeset
8447:200f4f1b7833
util.crand: Use a small buffer on the stack for small pieces of random, should be faster
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 03 Dec 2017 15:03:25 +0100 |
parents | 8446:a72898dde1a0 |
children | 8448:f516a52f19e8 |
files | util-src/crand.c |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util-src/crand.c Sun Dec 03 14:14:35 2017 +0100 +++ b/util-src/crand.c Sun Dec 03 15:03:25 2017 +0100 @@ -58,9 +58,19 @@ #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) /*