Index: src/utils.h |
diff --git a/src/utils.h b/src/utils.h |
index 785bc4373c8077b7d1850f117da67df1f13aebc8..5a3cd4cb0c07d6f0f5f1207c6876c8ae343434e6 100644 |
--- a/src/utils.h |
+++ b/src/utils.h |
@@ -497,9 +497,6 @@ class Collector { |
public: |
explicit Collector(int initial_capacity = kMinCapacity) |
: index_(0), size_(0) { |
- if (initial_capacity < kMinCapacity) { |
- initial_capacity = kMinCapacity; |
- } |
current_chunk_ = Vector<T>::New(initial_capacity); |
} |
@@ -601,13 +598,21 @@ class Collector { |
// Creates a new current chunk, and stores the old chunk in the chunks_ list. |
void Grow(int min_capacity) { |
ASSERT(growth_factor > 1); |
- int growth = current_chunk_.length() * (growth_factor - 1); |
- if (growth > max_growth) { |
- growth = max_growth; |
- } |
- int new_capacity = current_chunk_.length() + growth; |
- if (new_capacity < min_capacity) { |
- new_capacity = min_capacity + growth; |
+ int new_capacity; |
+ int current_length = current_chunk_.length(); |
+ if (current_length < kMinCapacity) { |
+ // The collector started out as empty. |
+ new_capacity = min_capacity * growth_factor; |
+ if (new_capacity < kMinCapacity) new_capacity = kMinCapacity; |
+ } else { |
+ int growth = current_length * (growth_factor - 1); |
+ if (growth > max_growth) { |
+ growth = max_growth; |
+ } |
+ new_capacity = current_length + growth; |
+ if (new_capacity < min_capacity) { |
+ new_capacity = min_capacity + growth; |
+ } |
} |
Vector<T> new_chunk = Vector<T>::New(new_capacity); |
int new_index = PrepareGrow(new_chunk); |