Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: src/js/math.js

Issue 1798863003: Revert of Allow Math.random to be called when creating a custom startup snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@testserialize
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/runtime/runtime-maths.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/math.js
diff --git a/src/js/math.js b/src/js/math.js
index 121d188101037fbda683c2e160364ec77a8cfbc8..fbe783bf7758b36daaa86ae10ad502c5db72cc81 100644
--- a/src/js/math.js
+++ b/src/js/math.js
@@ -10,6 +10,7 @@
// -------------------------------------------------------------------
// Imports
+define kRandomBatchSize = 64;
// The first two slots are reserved to persist PRNG state.
define kRandomNumberStart = 2;
@@ -18,7 +19,7 @@
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var NaN = %GetRootNaN();
-var nextRandomIndex = 0;
+var nextRandomIndex = kRandomBatchSize;
var randomNumbers = UNDEFINED;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
@@ -66,24 +67,19 @@
// ECMA 262 - 15.8.2.14
function MathRandom() {
- // While creating a startup snapshot, %GenerateRandomNumbers returns a
- // normal array containing a single random number, and has to be called for
- // every new random number.
- // Otherwise, it returns a pre-populated typed array of random numbers. The
- // first two elements are reserved for the PRNG state.
- if (nextRandomIndex <= kRandomNumberStart) {
+ if (nextRandomIndex >= kRandomBatchSize) {
randomNumbers = %GenerateRandomNumbers(randomNumbers);
- nextRandomIndex = randomNumbers.length;
- }
- return randomNumbers[--nextRandomIndex];
+ nextRandomIndex = kRandomNumberStart;
+ }
+ return randomNumbers[nextRandomIndex++];
}
function MathRandomRaw() {
- if (nextRandomIndex <= kRandomNumberStart) {
+ if (nextRandomIndex >= kRandomBatchSize) {
randomNumbers = %GenerateRandomNumbers(randomNumbers);
- nextRandomIndex = randomNumbers.length;
- }
- return %_DoubleLo(randomNumbers[--nextRandomIndex]) & 0x3FFFFFFF;
+ nextRandomIndex = kRandomNumberStart;
+ }
+ return %_DoubleLo(randomNumbers[nextRandomIndex++]) & 0x3FFFFFFF;
}
// ECMA 262 - 15.8.2.15
« no previous file with comments | « no previous file | src/runtime/runtime-maths.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698