diff --git a/src/quick-lint-js/container/byte-buffer.cpp b/src/quick-lint-js/container/byte-buffer.cpp index 96e5fbfc37..ea02b207f6 100644 --- a/src/quick-lint-js/container/byte-buffer.cpp +++ b/src/quick-lint-js/container/byte-buffer.cpp @@ -68,7 +68,10 @@ Byte_Buffer_Chunk make_chunk(const void* data, Byte_Buffer::Size_Type size) { } -Byte_Buffer::Byte_Buffer() { this->add_new_chunk(this->default_chunk_size); } +Byte_Buffer::Byte_Buffer() + : chunks_("Byte_Buffer::chunks_", new_delete_resource()) { + this->add_new_chunk(this->default_chunk_size); +} Byte_Buffer::Byte_Buffer(Byte_Buffer&&) = default; @@ -107,7 +110,7 @@ void Byte_Buffer::prepend_copy(String8_View data) { std::copy_n(data_bytes, data.size(), chunk_begin(prefix_chunk)); QLJS_ASSERT(end == chunk_end(prefix_chunk)); - this->chunks_.insert(this->chunks_.begin(), std::move(prefix_chunk)); + this->chunks_.push_front(std::move(prefix_chunk)); } void Byte_Buffer::clear() { @@ -123,7 +126,7 @@ void Byte_Buffer::clear() { Byte_Buffer::Size_Type Byte_Buffer::size() const { Size_Type total_size = 0; - for (std::size_t chunk_index = 0; chunk_index < this->chunks_.size() - 1; + for (Vector_Size chunk_index = 0; chunk_index < this->chunks_.size() - 1; ++chunk_index) { const Byte_Buffer_Chunk& c = this->chunks_[chunk_index]; total_size += chunk_size(c); @@ -136,7 +139,7 @@ bool Byte_Buffer::empty() const { if (this->bytes_used_in_current_chunk() > 0) { return false; } - for (std::size_t chunk_index = 0; chunk_index < this->chunks_.size() - 1; + for (Vector_Size chunk_index = 0; chunk_index < this->chunks_.size() - 1; ++chunk_index) { const Byte_Buffer_Chunk& c = this->chunks_[chunk_index]; if (chunk_size(c) > 0) { diff --git a/src/quick-lint-js/container/byte-buffer.h b/src/quick-lint-js/container/byte-buffer.h index 0b3b98c440..4eb87905b8 100644 --- a/src/quick-lint-js/container/byte-buffer.h +++ b/src/quick-lint-js/container/byte-buffer.h @@ -6,12 +6,12 @@ #include #include #include +#include #include #include #include #include #include -#include #if QLJS_HAVE_WRITEV #include @@ -89,7 +89,7 @@ class Byte_Buffer { template void enumerate_chunks(Func&& on_chunk) const { - for (std::size_t chunk_index = 0; chunk_index < this->chunks_.size(); + for (Vector_Size chunk_index = 0; chunk_index < this->chunks_.size(); ++chunk_index) { const Byte_Buffer_Chunk* c = &this->chunks_[chunk_index]; const std::byte* c_begin = @@ -128,7 +128,7 @@ class Byte_Buffer { static Byte_Buffer_Chunk allocate_chunk(Size_Type size); static void delete_chunk(Byte_Buffer_Chunk&&); - std::vector chunks_; + Vector chunks_; std::byte* cursor_; std::byte* current_chunk_end_; diff --git a/src/quick-lint-js/container/vector-profiler.h b/src/quick-lint-js/container/vector-profiler.h index b7f4cf2e42..8ba414f4b3 100644 --- a/src/quick-lint-js/container/vector-profiler.h +++ b/src/quick-lint-js/container/vector-profiler.h @@ -236,6 +236,10 @@ class Instrumented_Vector { return this->data_[index]; } + QLJS_FORCE_INLINE const value_type &operator[](size_type index) const { + return this->data_[index]; + } + QLJS_FORCE_INLINE value_type *begin() { return this->data(); } QLJS_FORCE_INLINE value_type *end() { return this->begin() + this->size(); } diff --git a/src/quick-lint-js/container/vector.h b/src/quick-lint-js/container/vector.h index d1d8651d81..858351a99f 100644 --- a/src/quick-lint-js/container/vector.h +++ b/src/quick-lint-js/container/vector.h @@ -186,6 +186,10 @@ class Raw_Vector { QLJS_ASSERT(index < this->size()); return this->data_[index]; } + const T &operator[](size_type index) const { + QLJS_ASSERT(index < this->size()); + return this->data_[index]; + } // Precondition: (none) void reserve(size_type new_capacity) {