Skip to content

Commit

Permalink
refactor: reduce code for operator[] of FlatMap (apache#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
wy1433 authored and Yang Liming committed Oct 31, 2023
1 parent 3c54843 commit ca4eddb
Showing 1 changed file with 1 addition and 16 deletions.
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

0 comments on commit ca4eddb

Please sign in to comment.