Title: [231347] trunk/Source/_javascript_Core
Revision
231347
Author
[email protected]
Date
2018-05-03 22:32:41 -0700 (Thu, 03 May 2018)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (231346 => 231347)


--- trunk/Source/_javascript_Core/ChangeLog	2018-05-04 05:28:12 UTC (rev 231346)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-05-04 05:32:41 UTC (rev 231347)
@@ -1,3 +1,21 @@
+2018-05-03  Yusuke Suzuki  <[email protected]>
+
+        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):
+
 2018-05-03  Saam Barati  <[email protected]>
 
         Don't prevent CreateThis being folded to NewObject when the structure is poly proto

Modified: trunk/Source/_javascript_Core/jit/BinarySwitch.cpp (231346 => 231347)


--- trunk/Source/_javascript_Core/jit/BinarySwitch.cpp	2018-05-04 05:28:12 UTC (rev 231346)
+++ trunk/Source/_javascript_Core/jit/BinarySwitch.cpp	2018-05-04 05:32:41 UTC (rev 231347)
@@ -137,6 +137,27 @@
     }
 }
 
+class RandomNumberGenerator {
+public:
+    using result_type = uint32_t;
+
+    RandomNumberGenerator(WeakRandom& weakRandom)
+        : m_weakRandom(weakRandom)
+    {
+    }
+
+    uint32_t operator()()
+    {
+        return m_weakRandom.getUint32();
+    }
+
+    static constexpr uint32_t min() { return std::numeric_limits<uint32_t>::min(); }
+    static constexpr uint32_t max() { return std::numeric_limits<uint32_t>::max(); }
+
+private:
+    WeakRandom& m_weakRandom;
+};
+
 void BinarySwitch::build(unsigned start, bool hardStart, unsigned end)
 {
     if (BinarySwitchInternal::verbose)
@@ -195,13 +216,9 @@
         for (unsigned i = 0; i < size; ++i)
             localCaseIndices.append(start + i);
         
-        std::random_shuffle(
+        std::shuffle(
             localCaseIndices.begin(), localCaseIndices.end(),
-            [this] (unsigned n) {
-                // We use modulo to get a random number in the range we want fully knowing that
-                // this introduces a tiny amount of bias, but we're fine with such tiny bias.
-                return m_weakRandom.getUint32() % n;
-            });
+            RandomNumberGenerator(m_weakRandom));
         
         for (unsigned i = 0; i < size - 1; ++i) {
             append(BranchCode(NotEqualToPush, localCaseIndices[i]));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to