This is an automated email from the ASF dual-hosted git repository.

guangmingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new ad077048 Fix infinite loop in flatmap resizing when bucket count is a 
power of two (#3071)
ad077048 is described below

commit ad0770483814cb8a79b14435e7c637bba4848927
Author: Chen Chuanle <60637740+git...@users.noreply.github.com>
AuthorDate: Mon Aug 25 17:09:08 2025 +0800

    Fix infinite loop in flatmap resizing when bucket count is a power of two 
(#3071)
---
 src/butil/containers/flat_map_inl.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/butil/containers/flat_map_inl.h 
b/src/butil/containers/flat_map_inl.h
index 13444b2e..93bcbf9d 100644
--- a/src/butil/containers/flat_map_inl.h
+++ b/src/butil/containers/flat_map_inl.h
@@ -714,8 +714,13 @@ template <typename _K, typename _T, typename _H, typename 
_E,
 optional<typename FlatMap<_K, _T, _H, _E, _S, _A, _M>::NewBucketsInfo>
 FlatMap<_K, _T, _H, _E, _S, _A, _M>::new_buckets_and_thumbnail(size_t size,
                                                                size_t 
new_nbucket) {
+    size_t bump = 0;
     do {
-        new_nbucket = flatmap_round(new_nbucket);
+        // The first iteration uses 'new_nbucket + 0' ensures that when 
new_nbucket is a power
+        // of 2 and is already sufficient to accommodate `size`, it does not 
need to be doubled.
+        // Subsequent use of 'new_nbucket + 1' avoids an infinite loop.
+        new_nbucket = flatmap_round(new_nbucket + bump);
+        bump = 1;
     } while (is_too_crowded(size, new_nbucket, _load_factor));
     if (_nbucket == new_nbucket) {
         return nullopt;


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to