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

Side by Side Diff: test/cctest/test-strings.cc

Issue 23548024: Introduce a RandonNumberGenerator class. Refactor the random/private_random uses in Isolate/Context. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-spaces.cc ('k') | test/cctest/test-strtod.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 23 matching lines...) Expand all
34 34
35 #include "v8.h" 35 #include "v8.h"
36 36
37 #include "api.h" 37 #include "api.h"
38 #include "factory.h" 38 #include "factory.h"
39 #include "objects.h" 39 #include "objects.h"
40 #include "cctest.h" 40 #include "cctest.h"
41 #include "zone-inl.h" 41 #include "zone-inl.h"
42 42
43 // Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry 43 // Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry
44 class RandomNumberGenerator { 44 class MyRandomNumberGenerator {
45 public: 45 public:
46 RandomNumberGenerator() { 46 MyRandomNumberGenerator() {
47 init(); 47 init();
48 } 48 }
49 49
50 void init(uint32_t seed = 0x5688c73e) { 50 void init(uint32_t seed = 0x5688c73e) {
51 static const uint32_t phi = 0x9e3779b9; 51 static const uint32_t phi = 0x9e3779b9;
52 c = 362436; 52 c = 362436;
53 i = kQSize-1; 53 i = kQSize-1;
54 Q[0] = seed; 54 Q[0] = seed;
55 Q[1] = seed + phi; 55 Q[1] = seed + phi;
56 Q[2] = seed + phi + phi; 56 Q[2] = seed + phi + phi;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 private: 127 private:
128 const char* data_; 128 const char* data_;
129 size_t length_; 129 size_t length_;
130 }; 130 };
131 131
132 132
133 static void InitializeBuildingBlocks(Handle<String>* building_blocks, 133 static void InitializeBuildingBlocks(Handle<String>* building_blocks,
134 int bb_length, 134 int bb_length,
135 bool long_blocks, 135 bool long_blocks,
136 RandomNumberGenerator* rng, 136 MyRandomNumberGenerator* rng,
137 Zone* zone) { 137 Zone* zone) {
138 // A list of pointers that we don't have any interest in cleaning up. 138 // A list of pointers that we don't have any interest in cleaning up.
139 // If they are reachable from a root then leak detection won't complain. 139 // If they are reachable from a root then leak detection won't complain.
140 Isolate* isolate = Isolate::Current(); 140 Isolate* isolate = Isolate::Current();
141 Factory* factory = isolate->factory(); 141 Factory* factory = isolate->factory();
142 for (int i = 0; i < bb_length; i++) { 142 for (int i = 0; i < bb_length; i++) {
143 int len = rng->next(16); 143 int len = rng->next(16);
144 int slice_head_chars = 0; 144 int slice_head_chars = 0;
145 int slice_tail_chars = 0; 145 int slice_tail_chars = 0;
146 int slice_depth = 0; 146 int slice_depth = 0;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 inline Handle<String> block(uint32_t offset); 269 inline Handle<String> block(uint32_t offset);
270 // Input variables. 270 // Input variables.
271 double early_termination_threshold_; 271 double early_termination_threshold_;
272 double leftness_; 272 double leftness_;
273 double rightness_; 273 double rightness_;
274 double empty_leaf_threshold_; 274 double empty_leaf_threshold_;
275 unsigned max_leaves_; 275 unsigned max_leaves_;
276 // Cached data. 276 // Cached data.
277 Handle<String> building_blocks_[kNumberOfBuildingBlocks]; 277 Handle<String> building_blocks_[kNumberOfBuildingBlocks];
278 String* empty_string_; 278 String* empty_string_;
279 RandomNumberGenerator rng_; 279 MyRandomNumberGenerator rng_;
280 // Stats. 280 // Stats.
281 ConsStringStats stats_; 281 ConsStringStats stats_;
282 unsigned early_terminations_; 282 unsigned early_terminations_;
283 private: 283 private:
284 DISALLOW_COPY_AND_ASSIGN(ConsStringGenerationData); 284 DISALLOW_COPY_AND_ASSIGN(ConsStringGenerationData);
285 }; 285 };
286 286
287 287
288 ConsStringGenerationData::ConsStringGenerationData(bool long_blocks, 288 ConsStringGenerationData::ConsStringGenerationData(bool long_blocks,
289 Zone* zone) { 289 Zone* zone) {
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 CheckCanonicalEquivalence(c, test); 1379 CheckCanonicalEquivalence(c, test);
1380 continue; 1380 continue;
1381 } 1381 }
1382 if (upper != c && lower != c) { 1382 if (upper != c && lower != c) {
1383 CheckCanonicalEquivalence(c, test); 1383 CheckCanonicalEquivalence(c, test);
1384 continue; 1384 continue;
1385 } 1385 }
1386 CHECK_EQ(Min(upper, lower), test); 1386 CHECK_EQ(Min(upper, lower), test);
1387 } 1387 }
1388 } 1388 }
OLDNEW
« no previous file with comments | « test/cctest/test-spaces.cc ('k') | test/cctest/test-strtod.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698