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

Side by Side Diff: runtime/lib/math_patch.dart

Issue 11419194: Improve performance of String.split for 1 and 0 character results. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/string_base.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // A VM patch of the dart:math library. 5 // A VM patch of the dart:math library.
6 patch num pow(num x, num exponent) { 6 patch num pow(num x, num exponent) {
7 if (exponent is int) { 7 if (exponent is int) {
8 return x.pow(exponent); 8 return x.pow(exponent);
9 } 9 }
10 // Double.pow will call exponent.toDouble(). 10 // Double.pow will call exponent.toDouble().
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 do { 44 do {
45 seed = (seed + 0x5A17) & _Random._MASK_64; 45 seed = (seed + 0x5A17) & _Random._MASK_64;
46 } while (seed == 0); 46 } while (seed == 0);
47 return new _Random._internal(seed); 47 return new _Random._internal(seed);
48 } 48 }
49 } 49 }
50 50
51 51
52 class _Random implements Random { 52 class _Random implements Random {
53 // Internal state of the random number generator. 53 // Internal state of the random number generator.
54 var _state; 54 final _state = new List(2);
55 static const kSTATE_LO = 0; 55 static const kSTATE_LO = 0;
56 static const kSTATE_HI = 1; 56 static const kSTATE_HI = 1;
57 57
58 _Random._internal(state) { 58 _Random._internal(state) {
59 _state = new List(2);
60 _state[kSTATE_LO] = state & _MASK_32; 59 _state[kSTATE_LO] = state & _MASK_32;
61 _state[kSTATE_HI] = state >> 32; 60 _state[kSTATE_HI] = state >> 32;
62 } 61 }
63 62
64 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32. 63 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32.
65 // http://en.wikipedia.org/wiki/Multiply-with-carry 64 // http://en.wikipedia.org/wiki/Multiply-with-carry
66 // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1. 65 // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1.
67 int _nextInt32() { 66 int _nextInt32() {
68 var state = ((_A * (_state[kSTATE_LO])) + _state[kSTATE_HI]) & _MASK_64; 67 var state = ((_A * (_state[kSTATE_LO])) + _state[kSTATE_HI]) & _MASK_64;
69 _state[kSTATE_LO] = state & _MASK_32; 68 _state[kSTATE_LO] = state & _MASK_32;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 110
112 static int _nextSeed() { 111 static int _nextSeed() {
113 if (_prng == null) { 112 if (_prng == null) {
114 // TODO(iposva): Use system to get a random seed. 113 // TODO(iposva): Use system to get a random seed.
115 _prng = new Random(new Date.now().millisecondsSinceEpoch); 114 _prng = new Random(new Date.now().millisecondsSinceEpoch);
116 } 115 }
117 // Trigger the PRNG once to change the internal state. 116 // Trigger the PRNG once to change the internal state.
118 return _prng._nextInt32(); 117 return _prng._nextInt32();
119 } 118 }
120 } 119 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string_base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698