enhance: reserve vector space to reduce reallocate cost in Views() and StringViews() (#37182)

issue: #37152

Signed-off-by: chasingegg <chao.gao@zilliz.com>
pull/37327/head
Gao 2024-10-31 10:02:21 +08:00 committed by GitHub
parent 6e37372619
commit 2092dc0ba1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 0 deletions

View File

@ -682,6 +682,7 @@ class SingleChunkVariableColumn : public SingleChunkColumnBase {
std::pair<std::vector<std::string_view>, FixedVector<bool>>
StringViews() const override {
std::vector<std::string_view> res;
res.reserve(num_rows_);
char* pos = data_;
for (size_t i = 0; i < num_rows_; ++i) {
uint32_t size;
@ -696,6 +697,7 @@ class SingleChunkVariableColumn : public SingleChunkColumnBase {
[[nodiscard]] std::vector<ViewType>
Views() const {
std::vector<ViewType> res;
res.reserve(num_rows_);
char* pos = data_;
for (size_t i = 0; i < num_rows_; ++i) {
uint32_t size;