Ignore:
Timestamp:
May 3, 2018, 10:32:41 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

Remove std::random_shuffle
https://bugs.webkit.org/show_bug.cgi?id=185292

Reviewed by Darin Adler.

std::random_shuffle is deprecated in C++14 and removed in C++17,
since std::random_shuffle relies on rand and srand.
Use std::shuffle instead.

  • jit/BinarySwitch.cpp:

(JSC::RandomNumberGenerator::RandomNumberGenerator):
(JSC::RandomNumberGenerator::operator()):
(JSC::RandomNumberGenerator::min):
(JSC::RandomNumberGenerator::max):
(JSC::BinarySwitch::build):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jit/BinarySwitch.cpp

    r221954 r231347  
    138138}
    139139
     140class RandomNumberGenerator {
     141public:
     142    using result_type = uint32_t;
     143
     144    RandomNumberGenerator(WeakRandom& weakRandom)
     145        : m_weakRandom(weakRandom)
     146    {
     147    }
     148
     149    uint32_t operator()()
     150    {
     151        return m_weakRandom.getUint32();
     152    }
     153
     154    static constexpr uint32_t min() { return std::numeric_limits<uint32_t>::min(); }
     155    static constexpr uint32_t max() { return std::numeric_limits<uint32_t>::max(); }
     156
     157private:
     158    WeakRandom& m_weakRandom;
     159};
     160
    140161void BinarySwitch::build(unsigned start, bool hardStart, unsigned end)
    141162{
     
    196217            localCaseIndices.append(start + i);
    197218       
    198         std::random_shuffle(
     219        std::shuffle(
    199220            localCaseIndices.begin(), localCaseIndices.end(),
    200             [this] (unsigned n) {
    201                 // We use modulo to get a random number in the range we want fully knowing that
    202                 // this introduces a tiny amount of bias, but we're fine with such tiny bias.
    203                 return m_weakRandom.getUint32() % n;
    204             });
     221            RandomNumberGenerator(m_weakRandom));
    205222       
    206223        for (unsigned i = 0; i < size - 1; ++i) {
Note: See TracChangeset for help on using the changeset viewer.