| OLD | NEW |
| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 #endif | 194 #endif |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 int length_; | 197 int length_; |
| 198 int data_length_; | 198 int data_length_; |
| 199 uint32_t* data_; | 199 uint32_t* data_; |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 class GrowableBitVector BASE_EMBEDDED { | 202 class GrowableBitVector BASE_EMBEDDED { |
| 203 public: | 203 public: |
| 204 class Iterator BASE_EMBEDDED { |
| 205 public: |
| 206 Iterator(const GrowableBitVector* target, Zone* zone) |
| 207 : it_(target->bits_ == NULL |
| 208 ? new(zone) BitVector(1, zone) |
| 209 : target->bits_) { } |
| 210 bool Done() const { return it_.Done(); } |
| 211 void Advance() { it_.Advance(); } |
| 212 int Current() const { return it_.Current(); } |
| 213 private: |
| 214 BitVector::Iterator it_; |
| 215 }; |
| 216 |
| 204 GrowableBitVector() : bits_(NULL) { } | 217 GrowableBitVector() : bits_(NULL) { } |
| 205 | 218 |
| 206 bool Contains(int value) const { | 219 bool Contains(int value) const { |
| 207 if (!InBitsRange(value)) return false; | 220 if (!InBitsRange(value)) return false; |
| 208 return bits_->Contains(value); | 221 return bits_->Contains(value); |
| 209 } | 222 } |
| 210 | 223 |
| 211 void Add(int value, Zone* zone) { | 224 void Add(int value, Zone* zone) { |
| 212 EnsureCapacity(value, zone); | 225 EnsureCapacity(value, zone); |
| 213 bits_->Add(value); | 226 bits_->Add(value); |
| 214 } | 227 } |
| 215 | 228 |
| 229 void Union(const GrowableBitVector& other, Zone* zone) { |
| 230 for (Iterator it(&other, zone); !it.Done(); it.Advance()) { |
| 231 Add(it.Current(), zone); |
| 232 } |
| 233 } |
| 234 |
| 235 void Clear() { if (bits_ != NULL) bits_->Clear(); } |
| 236 |
| 216 private: | 237 private: |
| 217 static const int kInitialLength = 1024; | 238 static const int kInitialLength = 1024; |
| 218 | 239 |
| 219 bool InBitsRange(int value) const { | 240 bool InBitsRange(int value) const { |
| 220 return bits_ != NULL && bits_->length() > value; | 241 return bits_ != NULL && bits_->length() > value; |
| 221 } | 242 } |
| 222 | 243 |
| 223 void EnsureCapacity(int value, Zone* zone) { | 244 void EnsureCapacity(int value, Zone* zone) { |
| 224 if (InBitsRange(value)) return; | 245 if (InBitsRange(value)) return; |
| 225 int new_length = bits_ == NULL ? kInitialLength : bits_->length(); | 246 int new_length = bits_ == NULL ? kInitialLength : bits_->length(); |
| 226 while (new_length <= value) new_length *= 2; | 247 while (new_length <= value) new_length *= 2; |
| 227 BitVector* new_bits = new(zone) BitVector(new_length, zone); | 248 BitVector* new_bits = new(zone) BitVector(new_length, zone); |
| 228 if (bits_ != NULL) new_bits->CopyFrom(*bits_); | 249 if (bits_ != NULL) new_bits->CopyFrom(*bits_); |
| 229 bits_ = new_bits; | 250 bits_ = new_bits; |
| 230 } | 251 } |
| 231 | 252 |
| 232 BitVector* bits_; | 253 BitVector* bits_; |
| 233 }; | 254 }; |
| 234 | 255 |
| 235 | 256 |
| 236 } } // namespace v8::internal | 257 } } // namespace v8::internal |
| 237 | 258 |
| 238 | 259 |
| 239 #endif // V8_DATAFLOW_H_ | 260 #endif // V8_DATAFLOW_H_ |
| OLD | NEW |