You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2015/12/21 20:44:58 UTC

[07/16] trafficserver git commit: TS-3418: Various style fixes.

TS-3418: Various style fixes.

Make various function declarations const where. Remove unnecessary
url_len argument from consistent hash lookup functions.

This closes #359.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b9bac0f2
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b9bac0f2
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b9bac0f2

Branch: refs/heads/6.1.x
Commit: b9bac0f28adf084b8b682f9176ea298bc48726ee
Parents: 0e7975a
Author: John J. Rushford <Jo...@cable.comcast.com>
Authored: Thu Dec 17 22:35:15 2015 +0000
Committer: James Peach <jp...@apache.org>
Committed: Thu Dec 17 20:23:49 2015 -0800

----------------------------------------------------------------------
 lib/ts/ConsistentHash.cc      | 20 ++++----------------
 lib/ts/ConsistentHash.h       |  4 ++--
 proxy/ParentConsistentHash.cc | 24 +++++++++---------------
 proxy/ParentConsistentHash.h  |  2 +-
 proxy/ParentRoundRobin.cc     |  2 +-
 proxy/ParentRoundRobin.h      |  2 +-
 proxy/ParentSelection.h       |  4 ++--
 7 files changed, 20 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/lib/ts/ConsistentHash.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ConsistentHash.cc b/lib/ts/ConsistentHash.cc
index fe919eb..6a46229 100644
--- a/lib/ts/ConsistentHash.cc
+++ b/lib/ts/ConsistentHash.cc
@@ -67,19 +67,13 @@ ATSConsistentHash::insert(ATSConsistentHashNode *node, float weight, ATSHash64 *
 }
 
 ATSConsistentHashNode *
-ATSConsistentHash::lookup(const char *url, size_t url_len, ATSConsistentHashIter *i, bool *w, ATSHash64 *h)
+ATSConsistentHash::lookup(const char *url, ATSConsistentHashIter *i, bool *w, ATSHash64 *h)
 {
   uint64_t url_hash;
   ATSConsistentHashIter NodeMapIterUp, *iter;
   ATSHash64 *thash;
   bool *wptr, wrapped = false;
 
-  if (url_len <= 0 && url) {
-    url_len = strlen(url);
-  } else {
-    url_len = 0;
-  }
-
   if (h) {
     thash = h;
   } else if (hash) {
@@ -101,7 +95,7 @@ ATSConsistentHash::lookup(const char *url, size_t url_len, ATSConsistentHashIter
   }
 
   if (url) {
-    thash->update(url, url_len);
+    thash->update(url, strlen(url));
     thash->final();
     url_hash = thash->get();
     thash->clear();
@@ -129,19 +123,13 @@ ATSConsistentHash::lookup(const char *url, size_t url_len, ATSConsistentHashIter
 }
 
 ATSConsistentHashNode *
-ATSConsistentHash::lookup_available(const char *url, size_t url_len, ATSConsistentHashIter *i, bool *w, ATSHash64 *h)
+ATSConsistentHash::lookup_available(const char *url, ATSConsistentHashIter *i, bool *w, ATSHash64 *h)
 {
   uint64_t url_hash;
   ATSConsistentHashIter NodeMapIterUp, *iter;
   ATSHash64 *thash;
   bool *wptr, wrapped = false;
 
-  if (url_len <= 0 && url) {
-    url_len = strlen(url);
-  } else {
-    url_len = 0;
-  }
-
   if (h) {
     thash = h;
   } else if (hash) {
@@ -163,7 +151,7 @@ ATSConsistentHash::lookup_available(const char *url, size_t url_len, ATSConsiste
   }
 
   if (url) {
-    thash->update(url, url_len);
+    thash->update(url, strlen(url));
     thash->final();
     url_hash = thash->get();
     thash->clear();

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/lib/ts/ConsistentHash.h
----------------------------------------------------------------------
diff --git a/lib/ts/ConsistentHash.h b/lib/ts/ConsistentHash.h
index 49822ad..5c1332b 100644
--- a/lib/ts/ConsistentHash.h
+++ b/lib/ts/ConsistentHash.h
@@ -49,9 +49,9 @@ typedef std::map<uint64_t, ATSConsistentHashNode *>::iterator ATSConsistentHashI
 struct ATSConsistentHash {
   ATSConsistentHash(int r = 1024, ATSHash64 *h = NULL);
   void insert(ATSConsistentHashNode *node, float weight = 1.0, ATSHash64 *h = NULL);
-  ATSConsistentHashNode *lookup(const char *url = NULL, size_t url_len = 0, ATSConsistentHashIter *i = NULL, bool *w = NULL,
+  ATSConsistentHashNode *lookup(const char *url = NULL, ATSConsistentHashIter *i = NULL, bool *w = NULL,
                                 ATSHash64 *h = NULL);
-  ATSConsistentHashNode *lookup_available(const char *url = NULL, size_t url_len = 0, ATSConsistentHashIter *i = NULL,
+  ATSConsistentHashNode *lookup_available(const char *url = NULL, ATSConsistentHashIter *i = NULL,
                                           bool *w = NULL, ATSHash64 *h = NULL);
   ATSConsistentHashNode *lookup_by_hashval(uint64_t hashval, ATSConsistentHashIter *i = NULL, bool *w = NULL);
   ~ATSConsistentHash();

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/proxy/ParentConsistentHash.cc
----------------------------------------------------------------------
diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc
index 48d7037..ca64ad9 100644
--- a/proxy/ParentConsistentHash.cc
+++ b/proxy/ParentConsistentHash.cc
@@ -30,7 +30,7 @@ ParentConsistentHash::ParentConsistentHash(ParentRecord *parent_record)
   parents[PRIMARY] = parent_record->parents;
   parents[SECONDARY] = parent_record->secondary_parents;
   ignore_query = parent_record->ignore_query;
-  memset(foundParents, 0, sizeof(foundParents));
+  ink_zero(foundParents);
 
   chash[PRIMARY] = new ATSConsistentHash();
 
@@ -54,12 +54,8 @@ ParentConsistentHash::ParentConsistentHash(ParentRecord *parent_record)
 
 ParentConsistentHash::~ParentConsistentHash()
 {
-  if (chash[PRIMARY]) {
-    delete chash[PRIMARY];
-  }
-  if (chash[SECONDARY]) {
-    delete chash[SECONDARY];
-  }
+  delete chash[PRIMARY];
+  delete chash[SECONDARY];
 }
 
 
@@ -135,16 +131,14 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir
       last_lookup = SECONDARY;
       fhash = chash[SECONDARY];
       path_hash = getPathHash(request_info, (ATSHash64 *)&hash);
-      if (path_hash) {
-        prtmp = (pRecord *)fhash->lookup_by_hashval(path_hash, &chashIter[last_lookup], &wrap_around[last_lookup]);
-        if (prtmp)
-          pRec = (parents[last_lookup] + prtmp->idx);
-      }
+      prtmp = (pRecord *)fhash->lookup_by_hashval(path_hash, &chashIter[last_lookup], &wrap_around[last_lookup]);
+      if (prtmp)
+        pRec = (parents[last_lookup] + prtmp->idx);
     } else {
       last_lookup = PRIMARY;
       fhash = chash[PRIMARY];
       do { // search until we've selected a different parent.
-        prtmp = (pRecord *)fhash->lookup(NULL, 0, &chashIter[last_lookup], &wrap_around[last_lookup], &hash);
+        prtmp = (pRecord *)fhash->lookup(NULL, &chashIter[last_lookup], &wrap_around[last_lookup], &hash);
         if (prtmp)
           pRec = (parents[last_lookup] + prtmp->idx);
       } while (prtmp && strcmp(prtmp->hostname, result->hostname) == 0);
@@ -184,7 +178,7 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir
           prtmp = (pRecord *)fhash->lookup_by_hashval(path_hash, &chashIter[last_lookup], &wrap_around[last_lookup]);
           firstCall = false;
         } else {
-          prtmp = (pRecord *)fhash->lookup(NULL, 0, &chashIter[last_lookup], &wrap_around[last_lookup], &hash);
+          prtmp = (pRecord *)fhash->lookup(NULL, &chashIter[last_lookup], &wrap_around[last_lookup], &hash);
         }
 
         if (prtmp) {
@@ -291,7 +285,7 @@ ParentConsistentHash::markParentDown(const ParentSelectionPolicy *policy, Parent
 }
 
 uint32_t
-ParentConsistentHash::numParents(ParentResult *result)
+ParentConsistentHash::numParents(ParentResult *result) const
 {
   uint32_t n = 0;
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/proxy/ParentConsistentHash.h
----------------------------------------------------------------------
diff --git a/proxy/ParentConsistentHash.h b/proxy/ParentConsistentHash.h
index ff09072..e86a65e 100644
--- a/proxy/ParentConsistentHash.h
+++ b/proxy/ParentConsistentHash.h
@@ -56,7 +56,7 @@ public:
   uint64_t getPathHash(HttpRequestData *hrdata, ATSHash64 *h);
   void selectParent(const ParentSelectionPolicy *policy, bool firstCall, ParentResult *result, RequestData *rdata);
   void markParentDown(const ParentSelectionPolicy *policy, ParentResult *result);
-  uint32_t numParents(ParentResult *result);
+  uint32_t numParents(ParentResult *result) const;
   void markParentUp(ParentResult *result);
 };
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/proxy/ParentRoundRobin.cc
----------------------------------------------------------------------
diff --git a/proxy/ParentRoundRobin.cc b/proxy/ParentRoundRobin.cc
index 44c050c..7971087 100644
--- a/proxy/ParentRoundRobin.cc
+++ b/proxy/ParentRoundRobin.cc
@@ -176,7 +176,7 @@ ParentRoundRobin::selectParent(const ParentSelectionPolicy *policy, bool first_c
 }
 
 uint32_t
-ParentRoundRobin::numParents(ParentResult *result)
+ParentRoundRobin::numParents(ParentResult *result) const
 {
   return result->rec->num_parents;
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/proxy/ParentRoundRobin.h
----------------------------------------------------------------------
diff --git a/proxy/ParentRoundRobin.h b/proxy/ParentRoundRobin.h
index e8c2755..57b6832 100644
--- a/proxy/ParentRoundRobin.h
+++ b/proxy/ParentRoundRobin.h
@@ -41,7 +41,7 @@ public:
   ~ParentRoundRobin();
   void selectParent(const ParentSelectionPolicy *policy, bool firstCall, ParentResult *result, RequestData *rdata);
   void markParentDown(const ParentSelectionPolicy *policy, ParentResult *result);
-  uint32_t numParents(ParentResult *result);
+  uint32_t numParents(ParentResult *result) const;
   void markParentUp(ParentResult *result);
 };
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b9bac0f2/proxy/ParentSelection.h
----------------------------------------------------------------------
diff --git a/proxy/ParentSelection.h b/proxy/ParentSelection.h
index d04b53b..c5b211d 100644
--- a/proxy/ParentSelection.h
+++ b/proxy/ParentSelection.h
@@ -179,7 +179,7 @@ public:
   //
   // Returns the number of parent records in a strategy.
   //
-  virtual uint32_t numParents(ParentResult *result) = 0;
+  virtual uint32_t numParents(ParentResult *result) const = 0;
 
   // void markParentUp
   //
@@ -197,7 +197,7 @@ class ParentConfigParams : public ConfigInfo
 public:
   P_table *parent_table;
   ParentRecord *DefaultParent;
-  ParentConfigParams(P_table *_parent_table);
+  explicit ParentConfigParams(P_table *_parent_table);
   ParentSelectionPolicy *policy;
   ~ParentConfigParams(){};