OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 } | 1279 } |
1280 | 1280 |
1281 | 1281 |
1282 // Simple sparse set with O(1) add, contains, and clear. | 1282 // Simple sparse set with O(1) add, contains, and clear. |
1283 class SparseSet { | 1283 class SparseSet { |
1284 public: | 1284 public: |
1285 SparseSet(Zone* zone, int capacity) | 1285 SparseSet(Zone* zone, int capacity) |
1286 : capacity_(capacity), | 1286 : capacity_(capacity), |
1287 length_(0), | 1287 length_(0), |
1288 dense_(zone->NewArray<int>(capacity)), | 1288 dense_(zone->NewArray<int>(capacity)), |
1289 sparse_(zone->NewArray<int>(capacity)) {} | 1289 sparse_(zone->NewArray<int>(capacity)) { |
| 1290 #ifndef NVALGRIND |
| 1291 // Initialize the sparse array to make valgrind happy. |
| 1292 memset(sparse_, 0, sizeof(sparse_[0]) * capacity); |
| 1293 #endif |
| 1294 } |
1290 | 1295 |
1291 bool Contains(int n) const { | 1296 bool Contains(int n) const { |
1292 ASSERT(0 <= n && n < capacity_); | 1297 ASSERT(0 <= n && n < capacity_); |
1293 int d = sparse_[n]; | 1298 int d = sparse_[n]; |
1294 return 0 <= d && d < length_ && dense_[d] == n; | 1299 return 0 <= d && d < length_ && dense_[d] == n; |
1295 } | 1300 } |
1296 | 1301 |
1297 bool Add(int n) { | 1302 bool Add(int n) { |
1298 if (Contains(n)) return false; | 1303 if (Contains(n)) return false; |
1299 dense_[length_] = n; | 1304 dense_[length_] = n; |
(...skipping 5102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6402 } | 6407 } |
6403 } | 6408 } |
6404 | 6409 |
6405 #ifdef DEBUG | 6410 #ifdef DEBUG |
6406 if (graph_ != NULL) graph_->Verify(); | 6411 if (graph_ != NULL) graph_->Verify(); |
6407 if (allocator_ != NULL) allocator_->Verify(); | 6412 if (allocator_ != NULL) allocator_->Verify(); |
6408 #endif | 6413 #endif |
6409 } | 6414 } |
6410 | 6415 |
6411 } } // namespace v8::internal | 6416 } } // namespace v8::internal |
OLD | NEW |