Index: src/utils.h |
diff --git a/src/utils.h b/src/utils.h |
index 62b8726b802ae30f8d0c64f9343d7849d3f98e9e..21e70d758e9df8e980fc439dbcafc3910e984f82 100644 |
--- a/src/utils.h |
+++ b/src/utils.h |
@@ -530,6 +530,24 @@ class Collector { |
} |
+ // Add a contiguous block of elements and return a vector backed |
+ // by the added block. |
+ // A basic Collector will keep this vector valid as long as the Collector |
+ // is alive. |
+ inline Vector<T> AddBlock(Vector<const T> source) { |
+ if (source.length() > current_chunk_.length() - index_) { |
+ Grow(source.length()); |
+ } |
+ T* position = current_chunk_.start() + index_; |
+ index_ += source.length(); |
+ size_ += source.length(); |
+ for (int i = 0; i < source.length(); i++) { |
+ position[i] = source[i]; |
+ } |
+ return Vector<T>(position, source.length()); |
+ } |
+ |
+ |
// Write the contents of the collector into the provided vector. |
void WriteTo(Vector<T> destination) { |
ASSERT(size_ <= destination.length()); |