diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-03-23 16:01:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-03-23 16:01:16 -0300 |
commit | 86e8039a72646cd9192fd08a6f1771c90b872ff6 (patch) | |
tree | e0c68d303aba023fc44d8e9193e239cbf7ae97f9 /lauxlib.c | |
parent | 5a04f1851e0d42b4bcbb0af103490bc964e985aa (diff) | |
download | lua-86e8039a72646cd9192fd08a6f1771c90b872ff6.tar.gz lua-86e8039a72646cd9192fd08a6f1771c90b872ff6.tar.bz2 lua-86e8039a72646cd9192fd08a6f1771c90b872ff6.zip |
Clock component removed from 'luaL_makeseed'
'clock' can be quite slow on some machines.
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -1094,8 +1094,8 @@ static void warnfon (void *ud, const char *message, int tocont) { | |||
1094 | 1094 | ||
1095 | /* | 1095 | /* |
1096 | ** A function to compute an unsigned int with some level of | 1096 | ** A function to compute an unsigned int with some level of |
1097 | ** randomness. Rely on Address Space Layout Randomization (if present), | 1097 | ** randomness. Rely on Address Space Layout Randomization (if present) |
1098 | ** current time, and clock. | 1098 | ** and the current time. |
1099 | */ | 1099 | */ |
1100 | #if !defined(luai_makeseed) | 1100 | #if !defined(luai_makeseed) |
1101 | 1101 | ||
@@ -1115,18 +1115,16 @@ static void warnfon (void *ud, const char *message, int tocont) { | |||
1115 | 1115 | ||
1116 | 1116 | ||
1117 | static unsigned int luai_makeseed (void) { | 1117 | static unsigned int luai_makeseed (void) { |
1118 | unsigned int buff[sof(void*) + sof(clock_t) + sof(time_t)]; | 1118 | unsigned int buff[sof(void*) + sof(time_t)]; |
1119 | unsigned int res; | 1119 | unsigned int res; |
1120 | unsigned int *b = buff; | 1120 | unsigned int *b = buff; |
1121 | clock_t c = clock(); | ||
1122 | time_t t = time(NULL); | 1121 | time_t t = time(NULL); |
1123 | void *h = buff; | 1122 | void *h = buff; |
1124 | addbuff(b, h); /* local variable's address */ | 1123 | addbuff(b, h); /* local variable's address */ |
1125 | addbuff(b, c); /* clock */ | ||
1126 | addbuff(b, t); /* time */ | 1124 | addbuff(b, t); /* time */ |
1127 | res = buff[0]; | 1125 | res = buff[0]; |
1128 | for (b = buff + 1; b < buff + sof(buff); b++) | 1126 | for (b = buff + 1; b < buff + sof(buff); b++) |
1129 | res += *b; | 1127 | res ^= (res >> 3) + (res << 7) + *b; |
1130 | return res; | 1128 | return res; |
1131 | } | 1129 | } |
1132 | 1130 | ||