This is an automated email from the ASF dual-hosted git repository.
jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 51bf10c2 fix issues in FlatMap
51bf10c2 is described below
commit 51bf10c214411cd490b6537659b24d91c50357fc
Author: gejun.0 <[email protected]>
AuthorDate: Thu Sep 29 18:49:25 2022 +0800
fix issues in FlatMap
---
src/butil/containers/flat_map_inl.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/butil/containers/flat_map_inl.h
b/src/butil/containers/flat_map_inl.h
index e5948920..ad5598c2 100644
--- a/src/butil/containers/flat_map_inl.h
+++ b/src/butil/containers/flat_map_inl.h
@@ -567,10 +567,12 @@ void FlatMap<_K, _T, _H, _E, _S>::save_iterator(
template <typename _K, typename _T, typename _H, typename _E, bool _S>
typename FlatMap<_K, _T, _H, _E, _S>::const_iterator
FlatMap<_K, _T, _H, _E, _S>::restore_iterator(const PositionHint& hint) const {
- if (hint.nbucket != _nbucket/*resized*/ ||
- hint.offset >= _nbucket/*invalid hint*/) {
- return begin(); // restart
- }
+ if (hint.nbucket != _nbucket) // resized
+ return begin(); // restart
+
+ if (hint.offset >= _nbucket) // invalid hint, stop the iteration
+ return end();
+
Bucket& first_node = _buckets[hint.offset];
if (hint.at_entry) {
return const_iterator(this, hint.offset);
@@ -604,6 +606,10 @@ bool FlatMap<_K, _T, _H, _E, _S>::resize(size_t nbucket2) {
}
FlatMap new_map;
+ // NOTE: following functors must be kept after resizing otherwise the
+ // internal state is lost.
+ new_map._hashfn = _hashfn;
+ new_map._eql = _eql;
if (new_map.init(nbucket2, _load_factor) != 0) {
LOG(ERROR) << "Fail to init new_map, nbucket=" << nbucket2;
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]