Skip to content

Commit

Permalink
Add autovector::reserve()
Browse files Browse the repository at this point in the history
  • Loading branch information
rockeet committed Sep 27, 2021
1 parent e4e84e1 commit c0aad3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions db/db_impl/db_impl.cc
Expand Up @@ -2297,6 +2297,7 @@ void DBImpl::MultiGet(const ReadOptions& read_options, const size_t num_keys,

autovector<KeyContext, MultiGetContext::MAX_BATCH_SIZE> key_context;
autovector<KeyContext*, MultiGetContext::MAX_BATCH_SIZE> sorted_keys;
key_context.reserve(num_keys);
sorted_keys.resize(num_keys);
for (size_t i = 0; i < num_keys; ++i) {
key_context.emplace_back(column_families[i], keys[i], &values[i],
Expand Down Expand Up @@ -2451,6 +2452,7 @@ void DBImpl::MultiGet(const ReadOptions& read_options,
}
autovector<KeyContext, MultiGetContext::MAX_BATCH_SIZE> key_context;
autovector<KeyContext*, MultiGetContext::MAX_BATCH_SIZE> sorted_keys;
key_context.reserve(num_keys);
sorted_keys.resize(num_keys);
for (size_t i = 0; i < num_keys; ++i) {
key_context.emplace_back(column_family, keys[i], &values[i],
Expand Down
6 changes: 6 additions & 0 deletions util/autovector.h
Expand Up @@ -220,6 +220,12 @@ class autovector {
}
}

void reserve(size_t cap) {
if (cap > kSize) {
vect_.reserve(cap - kSize);
}
}

bool empty() const { return size() == 0; }

const_reference operator[](size_type n) const {
Expand Down

0 comments on commit c0aad3c

Please sign in to comment.