1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* random.c (limited_rand): Add a specialized path for the limit fits in 32 bit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2016-02-24 12:30:20 +00:00
parent d4819da611
commit 169b867fbf
2 changed files with 24 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Wed Feb 24 21:03:04 2016 Tanaka Akira <akr@fsij.org>
* random.c (limited_rand): Add a specialized path for the limit fits
in 32 bit.
Tue Feb 23 21:52:24 2016 Martin Duerst <duerst@it.aoyama.ac.jp>
* enc/unicode/case-folding.rb, casefold.h: Outputting actual titlecase

View file

@ -826,11 +826,14 @@ static unsigned long
limited_rand(struct MT *mt, unsigned long limit)
{
/* mt must be initialized */
int i;
unsigned long val, mask;
if (!limit) return 0;
mask = make_mask(limit);
#if 4 < SIZEOF_LONG
if (0xffffffff < limit) {
int i;
retry:
val = 0;
for (i = SIZEOF_LONG/SIZEOF_INT32-1; 0 <= i; i--) {
@ -843,6 +846,13 @@ limited_rand(struct MT *mt, unsigned long limit)
}
return val;
}
#endif
do {
val = genrand_int32(mt) & mask;
} while (limit < val);
return val;
}
static VALUE
limited_big_rand(struct MT *mt, VALUE limit)