Parcourir la source

Save the RRset Hash Key instead of recalculating it everytime
Add private copy constructor and assignment operator to make it uncopyable

Ocean Wang il y a 14 ans
Parent
commit
0162b6441a
2 fichiers modifiés avec 22 ajouts et 10 suppressions
  1. 2 6
      src/lib/cache/rrset_entry.cc
  2. 20 4
      src/lib/cache/rrset_entry.h

+ 2 - 6
src/lib/cache/rrset_entry.cc

@@ -28,7 +28,8 @@ RRsetEntry::RRsetEntry(const isc::dns::RRset& rrset, const RRsetTrustLevel& leve
     entry_name_(genCacheEntryName(rrset.getName(), rrset.getType())),
     expire_time_(time(NULL) + rrset.getTTL().getValue()),
     trust_level_(level),
-    rrset_(new RRset(rrset.getName(), rrset.getClass(), rrset.getType(), rrset.getTTL()))
+    rrset_(new RRset(rrset.getName(), rrset.getClass(), rrset.getType(), rrset.getTTL())),
+    hash_key_(HashKey(entry_name_, rrset_->getClass()))
 {
     RdataIteratorPtr rdata_itor = rrset.getRdataIterator();
     rdata_itor->first();
@@ -54,11 +55,6 @@ RRsetEntry::getExpireTime() const {
     return expire_time_;
 }
 
-HashKey
-RRsetEntry::hashKey() const {
-    return HashKey(entry_name_, rrset_->getClass());
-}
-
 void
 RRsetEntry::updateTTL(){
     uint32_t oldTTL = rrset_->getTTL().getValue();

+ 20 - 4
src/lib/cache/rrset_entry.h

@@ -64,12 +64,25 @@ enum RRsetTrustLevel {
 /// entries.
 class RRsetEntry : public NsasEntry<RRsetEntry>
 {
+    ///
+    /// \name Constructors and Destructor
+    ///
+    /// Note: The copy constructor and the assignment operator are intentionally
+    /// defined as private to make it uncopyable
+    //@{
+private:
+    RRsetEntry(const RRsetEntry&);
+    RRsetEntry& operator=(const RRsetEntry&);
 public:
     /// \brief Constructor
     /// \param rrset The RRset used to initialize the RRset entry.
     /// \param level trustworthiness of the RRset.
     RRsetEntry(const isc::dns::RRset& rrset, const RRsetTrustLevel& level);
 
+    /// The destructor.
+    ~RRsetEntry() {}
+    //@}
+
     /// \brief Return a pointer to a generated RRset
     isc::dns::RRsetPtr getRRset();
 
@@ -83,7 +96,9 @@ public:
     }
 
     /// \return return hash key
-    virtual HashKey hashKey() const;
+    HashKey hashKey() const{
+        return hash_key_;
+    }
 
     /// \brief get RRset trustworthiness
     RRsetTrustLevel getTrustLevel() const {
@@ -94,10 +109,11 @@ private:
     void updateTTL();
 
 private:
-    std::string entry_name_; // the entry name for this rrset entry.
-    time_t expire_time_;    // Expiration time of rrset.
-    RRsetTrustLevel trust_level_; // rrset trustworthiness.
+    std::string entry_name_; // The entry name for this rrset entry.
+    time_t expire_time_;     // Expiration time of rrset.
+    RRsetTrustLevel trust_level_; // RRset trustworthiness.
     boost::shared_ptr<isc::dns::RRset> rrset_;
+    HashKey hash_key_;       // RRsetEntry hash key
 };
 
 typedef boost::shared_ptr<RRsetEntry> RRsetEntryPtr;