You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2018/10/18 17:59:53 UTC
[trafficserver] branch master updated: TCL: TCLHashTable in proxy
converted to use STL
This is an automated email from the ASF dual-hosted git repository.
amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new b95a38f TCL: TCLHashTable in proxy converted to use STL
b95a38f is described below
commit b95a38f7c98304c198fefbaf437632b2471cd52d
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Wed Oct 17 16:35:17 2018 -0500
TCL: TCLHashTable in proxy converted to use STL
---
proxy/ControlMatcher.cc | 14 +++++---------
proxy/ControlMatcher.h | 5 +++--
proxy/InkAPIInternal.h | 2 +-
proxy/http2/Http2ClientSession.cc | 6 ------
proxy/http2/Http2ClientSession.h | 15 ++++-----------
src/traffic_server/InkAPI.cc | 31 +++++++------------------------
6 files changed, 20 insertions(+), 53 deletions(-)
diff --git a/proxy/ControlMatcher.cc b/proxy/ControlMatcher.cc
index 85cb7de..8034ecf 100644
--- a/proxy/ControlMatcher.cc
+++ b/proxy/ControlMatcher.cc
@@ -234,7 +234,6 @@ HostMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
template <class Data, class MatchResult>
UrlMatcher<Data, MatchResult>::UrlMatcher(const char *name, const char *filename) : BaseMatcher<Data>(name, filename)
{
- url_ht = ink_hash_table_create(InkHashTableKeyType_String);
}
//
@@ -242,7 +241,6 @@ UrlMatcher<Data, MatchResult>::UrlMatcher(const char *name, const char *filename
//
template <class Data, class MatchResult> UrlMatcher<Data, MatchResult>::~UrlMatcher()
{
- ink_hash_table_destroy(url_ht);
for (int i = 0; i < num_el; i++) {
ats_free(url_str[i]);
}
@@ -293,7 +291,6 @@ UrlMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
{
Data *cur_d;
char *pattern;
- int *value;
Result error = Result::ok();
// Make sure space has been allocated
@@ -308,7 +305,7 @@ UrlMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
ink_assert(line_info->dest_entry < MATCHER_MAX_TOKENS);
ink_assert(pattern != nullptr);
- if (ink_hash_table_lookup(url_ht, pattern, (void **)&value)) {
+ if (url_ht.find(pattern) != url_ht.end()) {
return Result::failure("%s url expression error (have exist) at line %d position", matcher_name, line_info->line_num);
}
@@ -322,7 +319,7 @@ UrlMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
if (error.failed()) {
url_str[num_el] = ats_strdup(pattern);
url_value[num_el] = num_el;
- ink_hash_table_insert(url_ht, url_str[num_el], (void *)&url_value[num_el]);
+ url_ht.emplace(url_str[num_el], url_value[num_el]);
num_el++;
}
@@ -340,7 +337,6 @@ void
UrlMatcher<Data, MatchResult>::Match(RequestData *rdata, MatchResult *result)
{
char *url_str;
- int *value;
// Check to see there is any work to before we copy the
// URL
@@ -356,9 +352,9 @@ UrlMatcher<Data, MatchResult>::Match(RequestData *rdata, MatchResult *result)
url_str = ats_strdup("");
}
- if (ink_hash_table_lookup(url_ht, url_str, (void **)&value)) {
- Debug("matcher", "%s Matched %s with url at line %d", matcher_name, url_str, data_array[*value].line_num);
- data_array[*value].UpdateMatch(result, rdata);
+ if (auto it = url_ht.find(url_str); it != url_ht.end()) {
+ Debug("matcher", "%s Matched %s with url at line %d", matcher_name, url_str, data_array[it->second].line_num);
+ data_array[it->second].UpdateMatch(result, rdata);
}
ats_free(url_str);
diff --git a/proxy/ControlMatcher.h b/proxy/ControlMatcher.h
index b47085e..16dc8ec 100644
--- a/proxy/ControlMatcher.h
+++ b/proxy/ControlMatcher.h
@@ -87,7 +87,6 @@
#pragma once
#include "tscore/DynArray.h"
-#include "tscore/ink_hash_table.h"
#include "tscore/IpMap.h"
#include "tscore/Result.h"
#include "tscore/MatcherUtils.h"
@@ -98,6 +97,8 @@
#include "tscore/Regex.h"
#include "URL.h"
+#include <unordered_map>
+
#ifdef HAVE_CTYPE_H
#include <cctype>
#endif
@@ -203,7 +204,7 @@ public:
using super::array_len;
private:
- InkHashTable *url_ht;
+ std::unordered_map<std::string, int> url_ht;
char **url_str = nullptr; // array of url strings
int *url_value = nullptr; // array of posion of url strings
};
diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h
index 99aaec2..b86b4cb 100644
--- a/proxy/InkAPIInternal.h
+++ b/proxy/InkAPIInternal.h
@@ -335,7 +335,7 @@ public:
void invoke(INKContInternal *contp);
private:
- InkHashTable *cb_table;
+ std::unordered_map<std::string, INKContInternal *> cb_table;
};
void api_init();
diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc
index d4e9c45..f6a1ff0 100644
--- a/proxy/http2/Http2ClientSession.cc
+++ b/proxy/http2/Http2ClientSession.cc
@@ -74,10 +74,6 @@ Http2ClientSession::destroy()
void
Http2ClientSession::free()
{
- if (h2_pushed_urls) {
- this->h2_pushed_urls = ink_hash_table_destroy(this->h2_pushed_urls);
- }
-
if (client_vc) {
client_vc->do_io_close();
client_vc = nullptr;
@@ -181,8 +177,6 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB
this->read_buffer = iobuf ? iobuf : new_MIOBuffer(HTTP2_HEADER_BUFFER_SIZE_INDEX);
this->read_buffer->water_mark = connection_state.server_settings.get(HTTP2_SETTINGS_MAX_FRAME_SIZE);
this->sm_reader = reader ? reader : this->read_buffer->alloc_reader();
- this->h2_pushed_urls = ink_hash_table_create(InkHashTableKeyType_String);
- this->h2_pushed_urls_size = 0;
this->write_buffer = new_MIOBuffer(HTTP2_HEADER_BUFFER_SIZE_INDEX);
this->sm_writer = this->write_buffer->alloc_reader();
diff --git a/proxy/http2/Http2ClientSession.h b/proxy/http2/Http2ClientSession.h
index 092b409..dc927d4 100644
--- a/proxy/http2/Http2ClientSession.h
+++ b/proxy/http2/Http2ClientSession.h
@@ -284,20 +284,14 @@ public:
bool
is_url_pushed(const char *url, int url_len)
{
- char *dup_url = ats_strndup(url, url_len);
- InkHashTableEntry *entry = ink_hash_table_lookup_entry(h2_pushed_urls, dup_url);
- ats_free(dup_url);
- return entry != nullptr;
+ return h2_pushed_urls.find(url) != h2_pushed_urls.end();
}
void
add_url_to_pushed_table(const char *url, int url_len)
{
- if (h2_pushed_urls_size < Http2::push_diary_size) {
- char *dup_url = ats_strndup(url, url_len);
- ink_hash_table_insert(h2_pushed_urls, dup_url, nullptr);
- h2_pushed_urls_size++;
- ats_free(dup_url);
+ if (h2_pushed_urls.size() < Http2::push_diary_size) {
+ h2_pushed_urls.emplace(url);
}
}
@@ -345,8 +339,7 @@ private:
bool half_close_local = false;
int recursion = 0;
- InkHashTable *h2_pushed_urls = nullptr;
- uint32_t h2_pushed_urls_size = 0;
+ std::unordered_set<std::string> h2_pushed_urls;
};
extern ClassAllocator<Http2ClientSession> http2ClientSessionAllocator;
diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc
index d022d4d..74e8fbb 100644
--- a/src/traffic_server/InkAPI.cc
+++ b/src/traffic_server/InkAPI.cc
@@ -1353,50 +1353,33 @@ APIHooks::clear()
//
////////////////////////////////////////////////////////////////////
-ConfigUpdateCbTable::ConfigUpdateCbTable()
-{
- cb_table = ink_hash_table_create(InkHashTableKeyType_String);
-}
+ConfigUpdateCbTable::ConfigUpdateCbTable() {}
-ConfigUpdateCbTable::~ConfigUpdateCbTable()
-{
- ink_assert(cb_table != nullptr);
-
- ink_hash_table_destroy(cb_table);
-}
+ConfigUpdateCbTable::~ConfigUpdateCbTable() {}
void
ConfigUpdateCbTable::insert(INKContInternal *contp, const char *name)
{
- ink_assert(cb_table != nullptr);
-
if (contp && name) {
- ink_hash_table_insert(cb_table, (InkHashTableKey)name, (InkHashTableValue)contp);
+ cb_table.emplace(name, contp);
}
}
void
ConfigUpdateCbTable::invoke(const char *name)
{
- ink_assert(cb_table != nullptr);
-
- InkHashTableIteratorState ht_iter;
- InkHashTableEntry *ht_entry;
INKContInternal *contp;
if (name != nullptr) {
if (strcmp(name, "*") == 0) {
- ht_entry = ink_hash_table_iterator_first(cb_table, &ht_iter);
- while (ht_entry != nullptr) {
- contp = (INKContInternal *)ink_hash_table_entry_value(cb_table, ht_entry);
+ for (auto &&it : cb_table) {
+ contp = it.second;
ink_assert(contp != nullptr);
invoke(contp);
- ht_entry = ink_hash_table_iterator_next(cb_table, &ht_iter);
}
} else {
- ht_entry = ink_hash_table_lookup_entry(cb_table, (InkHashTableKey)name);
- if (ht_entry != nullptr) {
- contp = (INKContInternal *)ink_hash_table_entry_value(cb_table, ht_entry);
+ if (auto it = cb_table.find(name); it != cb_table.end()) {
+ contp = it->second;
ink_assert(contp != nullptr);
invoke(contp);
}