Repository: trafficserver
Updated Branches:
  refs/heads/master bb685f9e4 -> 8ed6e6f52


atscppapi: Optimizing values() in Headers by removing size()/count() calls


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

Branch: refs/heads/master
Commit: 8ed6e6f526ec13dff01ca04f5ab0503ba41341d4
Parents: bb685f9
Author: Manjesh Nilange <manjeshnila...@yahoo.com>
Authored: Tue Aug 19 13:20:59 2014 -0700
Committer: Manjesh Nilange <manjeshnila...@yahoo.com>
Committed: Tue Aug 19 13:20:59 2014 -0700

----------------------------------------------------------------------
 .../examples/clientrequest/ClientRequest.cc      |  1 +
 lib/atscppapi/src/Headers.cc                     | 19 ++++++++-----------
 2 files changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8ed6e6f5/lib/atscppapi/examples/clientrequest/ClientRequest.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/examples/clientrequest/ClientRequest.cc 
b/lib/atscppapi/examples/clientrequest/ClientRequest.cc
index 3a2524c..31cd789 100644
--- a/lib/atscppapi/examples/clientrequest/ClientRequest.cc
+++ b/lib/atscppapi/examples/clientrequest/ClientRequest.cc
@@ -106,6 +106,7 @@ public:
     cout << "Joining on a non-existant header gives: " << 
client_request_headers.values("i_dont_exist") << endl;
     cout << "Joining the accept encoding header gives: " << 
client_request_headers.values("accept-encoding") << endl;
     cout << "Joining the accept encoding header with space gives: " << 
client_request_headers.values("accept-encoding", ' ') << endl;
+    cout << "Joining the accept encoding header with long join string gives: " 
<< client_request_headers.values("accept-encoding", "--join-string--") << endl;
 
     transaction.resume();
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8ed6e6f5/lib/atscppapi/src/Headers.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/Headers.cc b/lib/atscppapi/src/Headers.cc
index 96afbb9..0cdb089 100644
--- a/lib/atscppapi/src/Headers.cc
+++ b/lib/atscppapi/src/Headers.cc
@@ -194,14 +194,14 @@ HeaderFieldName HeaderField::name() const {
 }
 
 std::string HeaderField::values(const char *join) {
-  std::ostringstream oss;
-  int count = size();
+  std::string ret; 
   for(header_field_value_iterator it = begin(); it != end(); ++it) {
-    oss << (*it);
-    if (--count > 0)
-      oss << join;
+    if (ret.size()) {
+      ret.append(join);
+    }
+    ret.append(*it);
   }
-  return oss.str();
+  return ret;
 }
 
 std::string HeaderField::values(const std::string &join) {
@@ -472,14 +472,11 @@ Headers::size_type Headers::count(const std::string &key) 
{
 
 std::string Headers::values(const std::string &key, const char *join) {
   std::string ret;
-  Headers::size_type num_header_fields = count(key);
-  ret.reserve(128 * num_header_fields);
-
   for (header_field_iterator it = find(key); it != end(); it.nextDup()) {
-    ret.append((*it).values(join));
-    if (--num_header_fields > 0) {
+    if (ret.size()) {
       ret.append(join);
     }
+    ret.append((*it).values(join));
   }
 
   return ret;

Reply via email to