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

Unified Diff: lib/math_patch.dart

Issue 11339027: - Avoid going into BigInteger domain for most of the Random state calculation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/math_patch.dart
===================================================================
--- lib/math_patch.dart (revision 14219)
+++ lib/math_patch.dart (working copy)
@@ -33,16 +33,20 @@
class _Random implements Random {
// Internal state of the random number generator.
- var _state;
+ var _state_lo;
+ var _state_hi;
- _Random._internal(this._state);
+ _Random._internal(state)
srdjan 2012/10/30 00:16:58 you can type this int.
+ : _state_lo = (state & _MASK_32), _state_hi = (state >> 32);
// The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32.
// http://en.wikipedia.org/wiki/Multiply-with-carry
// The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1.
int _nextInt32() {
- _state = ((_A * (_state & _MASK_32)) + (_state >> 32)) & _MASK_64;
- return _state & _MASK_32;
+ var state = ((_A * (_state_lo)) + _state_hi) & _MASK_64;
+ _state_lo = state & _MASK_32;
+ _state_hi = state >> 32;
+ return _state_lo;
}
int nextInt(int max) {
@@ -89,7 +93,6 @@
_prng = new Random(new Date.now().millisecondsSinceEpoch);
}
// Trigger the PRNG once to change the internal state.
- _prng._nextInt32();
- return _prng._state;
+ return _prng._nextInt32();
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698