From: Sage Weil Date: Tue, 6 Jun 2017 18:50:46 +0000 (-0400) Subject: common/LogEntry: make LogEntryKey opaque and cache its hash value X-Git-Tag: v12.1.0~247^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cb1f57c5c3af4e2ece83afbb38a146eb8b966526;p=ceph.git common/LogEntry: make LogEntryKey opaque and cache its hash value This avoids recalculating. We eliminate the default ctor at the same time and make the type totally opaque (so that its fields cannot be modified except by the ctor and decode). Signed-off-by: Sage Weil --- diff --git a/src/common/LogEntry.cc b/src/common/LogEntry.cc index 52af1eb878d7..40bdbea2b3ac 100644 --- a/src/common/LogEntry.cc +++ b/src/common/LogEntry.cc @@ -20,6 +20,7 @@ void LogEntryKey::decode(bufferlist::iterator& bl) ::decode(who, bl); ::decode(stamp, bl); ::decode(seq, bl); + _calc_hash(); } void LogEntryKey::dump(Formatter *f) const diff --git a/src/common/LogEntry.h b/src/common/LogEntry.h index 5d00119d7805..7d6446a66ea4 100644 --- a/src/common/LogEntry.h +++ b/src/common/LogEntry.h @@ -54,28 +54,44 @@ string clog_type_to_string(clog_type t); struct LogEntryKey { +private: + uint64_t _hash; + + void _calc_hash() { + hash h; + _hash = seq + h(who); + } + entity_inst_t who; utime_t stamp; - uint64_t seq; + uint64_t seq = 0; + +public: + LogEntryKey() {} + LogEntryKey(const entity_inst_t& w, utime_t t, uint64_t s) + : who(w), stamp(t), seq(s) { + _calc_hash(); + } - LogEntryKey() : seq(0) {} - LogEntryKey(const entity_inst_t& w, utime_t t, uint64_t s) : who(w), stamp(t), seq(s) {} + uint64_t get_hash() const { + return _hash; + } void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(list& o); + + friend bool operator==(const LogEntryKey& l, const LogEntryKey& r) { + return l.who == r.who && l.stamp == r.stamp && l.seq == r.seq; + } }; WRITE_CLASS_ENCODER_FEATURES(LogEntryKey) -static inline bool operator==(const LogEntryKey& l, const LogEntryKey& r) { - return l.who == r.who && l.stamp == r.stamp && l.seq == r.seq; -} namespace std { template<> struct hash { size_t operator()(const LogEntryKey& r) const { - hash h; - return r.seq + h(r.who); + return r.get_hash(); } }; } // namespace std