Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reduce code for operator[] of FlatMap #2202

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/butil/containers/flat_map_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,7 @@ _T& FlatMap<_K, _T, _H, _E, _S, _A>::operator[](const key_type& key) {
new (&first_node) Bucket(key);
return first_node.element().second_ref();
}
if (_eql(first_node.element().first_ref(), key)) {
return first_node.element().second_ref();
}
Bucket *p = first_node.next;
if (NULL == p) {
if (is_too_crowded(_size)) {
if (resize(_nbucket + 1)) {
return operator[](key);
}
// fail to resize is OK
}
++_size;
Bucket* newp = new (_pool.get()) Bucket(key);
first_node.next = newp;
return newp->element().second_ref();
}
Bucket *p = &first_node;
while (1) {
if (_eql(p->element().first_ref(), key)) {
return p->element().second_ref();
Expand Down