ruby-changes:63328
From: Yusuke <ko1@a...>
Date: Mon, 12 Oct 2020 13:50:32 +0900 (JST)
Subject: [ruby-changes:63328] eb21e8add3 (master): bignum.c (bary_sparse_p): do not comsume Random::DEFAULT
https://git.ruby-lang.org/ruby.git/commit/?id=eb21e8add3 From eb21e8add346854aa93299bf767f119439f74f7a Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Mon, 12 Oct 2020 13:45:32 +0900 Subject: bignum.c (bary_sparse_p): do not comsume Random::DEFAULT It uses random to determine if the bignum is sparse or not. It is arguable if three-digit samples are enough or not to determine it, but anyway, consuming Random source implicitly is not good. I introduced the random sampling mechanism, and I don't know any significant reason to do so. So, let's remove it. This change makes the sampling points fixed: 40th, 50th, and 60th percentiles. diff --git a/bignum.c b/bignum.c index cd969ac..0515e2f 100644 --- a/bignum.c +++ b/bignum.c @@ -2359,9 +2359,9 @@ bary_sparse_p(const BDIGIT *ds, size_t n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2359 { long c = 0; - if ( ds[rb_genrand_ulong_limited(n / 2) + n / 4]) c++; - if (c <= 1 && ds[rb_genrand_ulong_limited(n / 2) + n / 4]) c++; - if (c <= 1 && ds[rb_genrand_ulong_limited(n / 2) + n / 4]) c++; + if ( ds[2 * n / 5]) c++; + if (c <= 1 && ds[ n / 2]) c++; + if (c <= 1 && ds[3 * n / 5]) c++; return (c <= 1) ? 1 : 0; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/