jamesge commented on a change in pull request #1128:
URL: https://github.com/apache/incubator-brpc/pull/1128#discussion_r436529673
##########
File path: src/brpc/redis.h
##########
@@ -224,11 +225,13 @@ class RedisService {
bool AddCommandHandler(const std::string& name, RedisCommandHandler*
handler);
// This function should not be touched by user and used by brpc deverloper
only.
- RedisCommandHandler* FindCommandHandler(const std::string& name) const;
+ RedisCommandHandler* FindCommandHandler(const butil::StringPiece& name)
const;
private:
- typedef std::unordered_map<std::string, RedisCommandHandler*> CommandMap;
+ typedef BUTIL_HASH_NAMESPACE::hash<butil::StringPiece> StringPieceHasher;
+ typedef std::unordered_map<butil::StringPiece, RedisCommandHandler*,
StringPieceHasher> CommandMap;
Review comment:
这依赖于std::list的内存管理,如果后续不知情的人换成vector,在resize后其中元素的地址可能就都变了,从而引发bug。另外,这里的“存"其实不是瓶颈,用string就行了(除非是极度热点的地方),查目前也可以用string,以后觉得是热点再换不迟。
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]