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 2022/04/20 15:39:18 UTC

[trafficserver] branch 9.2.x updated: Avoid allocation when matching hosts for vol lookup (#8762)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new 953b209a8 Avoid allocation when matching hosts for vol lookup (#8762)
953b209a8 is described below

commit 953b209a8ce771f88d825d2b5722a76fc5212e64
Author: Chris McFarlen <ch...@mcfarlen.us>
AuthorDate: Tue Mar 29 10:10:37 2022 -0500

    Avoid allocation when matching hosts for vol lookup (#8762)
    
    Co-authored-by: Chris McFarlen <cm...@apple.com>
    (cherry picked from commit f30f442d8d8c14fe8db5e6c4d90fb6ea08404b4b)
---
 iocore/cache/CacheHosting.cc  | 9 +++------
 iocore/cache/P_CacheHosting.h | 2 +-
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc
index e98793fa1..60cb68909 100644
--- a/iocore/cache/CacheHosting.cc
+++ b/iocore/cache/CacheHosting.cc
@@ -112,9 +112,7 @@ CacheHostMatcher::Match(const char *rdata, int rlen, CacheHostResult *result) co
     return;
   }
 
-  char *data = static_cast<char *>(ats_malloc(rlen + 1));
-  memcpy(data, rdata, rlen);
-  *(data + rlen) = '\0';
+  std::string_view data{rdata, static_cast<size_t>(rlen)};
   HostLookupState s;
 
   r = host_lookup->MatchFirst(data, &s, &opaque_ptr);
@@ -122,11 +120,10 @@ CacheHostMatcher::Match(const char *rdata, int rlen, CacheHostResult *result) co
   while (r == true) {
     ink_assert(opaque_ptr != nullptr);
     data_ptr = static_cast<CacheHostRecord *>(opaque_ptr);
-    data_ptr->UpdateMatch(result, data);
+    data_ptr->UpdateMatch(result);
 
     r = host_lookup->MatchNext(&s, &opaque_ptr);
   }
-  ats_free(data);
 }
 
 //
@@ -577,7 +574,7 @@ CacheHostRecord::Init(matcher_line *line_info, CacheType typ)
 }
 
 void
-CacheHostRecord::UpdateMatch(CacheHostResult *r, char * /* rd ATS_UNUSED */)
+CacheHostRecord::UpdateMatch(CacheHostResult *r)
 {
   r->record = this;
 }
diff --git a/iocore/cache/P_CacheHosting.h b/iocore/cache/P_CacheHosting.h
index e6eaa764e..ba6fecd81 100644
--- a/iocore/cache/P_CacheHosting.h
+++ b/iocore/cache/P_CacheHosting.h
@@ -38,7 +38,7 @@ struct CacheHostRecord {
   int Init(CacheType typ);
   int Init(matcher_line *line_info, CacheType typ);
 
-  void UpdateMatch(CacheHostResult *r, char *rd);
+  void UpdateMatch(CacheHostResult *r);
   void Print() const;
 
   ~CacheHostRecord()