From ca4eddbb6e8bc0dfc5d632edf626ff0e39dd0875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8B=87?= Date: Wed, 26 Apr 2023 11:32:10 +0800 Subject: [PATCH] refactor: reduce code for operator[] of FlatMap (#2202) --- src/butil/containers/flat_map_inl.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/butil/containers/flat_map_inl.h b/src/butil/containers/flat_map_inl.h index f79fcb86c9..264d28c753 100644 --- a/src/butil/containers/flat_map_inl.h +++ b/src/butil/containers/flat_map_inl.h @@ -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();