From eeb5dce7dc9a4f4fdb49b6de62252ae25b6be490 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Mon, 28 Mar 2022 15:23:21 -0500 Subject: [PATCH] Avoid allocation when matching hosts for vol lookup --- 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 e98793fa18e..60cb6890929 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(ats_malloc(rlen + 1)); - memcpy(data, rdata, rlen); - *(data + rlen) = '\0'; + std::string_view data{rdata, static_cast(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(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 e6eaa764edf..ba6fecd812d 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()