chenBright opened a new pull request, #2620:
URL: https://github.com/apache/brpc/pull/2620

   ### What problem does this PR solve?
   
   Issue Number:
   
   Problem Summary:
   
   目前FlatMap是两阶段初始化:构造函数+init函数。这种初始化方式很容易用错并出core,所以使用上必须小心翼翼,体验不好。例如以下代码:
   ```
   butil::FlatMap<int, int> m1;
   if (m1.init(32) != 0) {}
   butil::FlatMap<int, int> m2 = m1;
   ```
   根据`operator=`可知,即使m1已经初始化了,但是因为m1是空的,所以将m1赋值给m2后,m2仍然是未初始化的,一旦被使用,基本上就会出core。
   
https://github.com/apache/brpc/blob/68aff6947c10d92bf44aa585b1913deb91cf8f92/src/butil/containers/flat_map_inl.h#L265-L274
   
   当然上述例子是bug,但是可以反映出目前FlatMap使用上的不便性和易错性。
   
   ### What is changed and the side effects?
   
   Changed:
   
   
FlatMap构造完成即完成初始化。使用sso、IOBuf::SmallView的策略,初始化_buckets和_thumbnail使用类内的内存块,没有init函数中Alloc失败的顾虑。
   
   Side effects:
   - Performance effects(性能影响):
   
   - Breaking backward compatibility(向后兼容性): 
   
   ---
   ### Check List:
   - Please make sure your changes are compilable(请确保你的更改可以通过编译).
   - When providing us with a new feature, it is best to add related 
tests(如果你向我们增加一个新的功能, 请添加相关测试).
   - Please follow [Contributor Covenant Code of 
Conduct](../../master/CODE_OF_CONDUCT.md).(请遵循贡献者准则).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to