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 eb0a5ca Cleanup: Replace Dynarray by std::vector
eb0a5ca is described below
commit eb0a5ca74c0587e42063613516c9e423a704402e
Author: Xavier Chi <[email protected]>
AuthorDate: Thu Nov 1 16:12:17 2018 -0500
Cleanup: Replace Dynarray by std::vector
---
include/tscore/DynArray.h | 191 ----------------------------------------
proxy/ControlMatcher.h | 1 -
proxy/RegressionSM.cc | 61 ++++++-------
proxy/RegressionSM.h | 23 +++--
proxy/hdrs/HdrHeap.cc | 3 +-
proxy/hdrs/HdrHeap.h | 1 +
proxy/http/HttpPages.h | 1 -
src/traffic_server/CoreUtils.cc | 72 +++++----------
src/traffic_server/CoreUtils.h | 1 -
src/tscore/Makefile.am | 1 -
10 files changed, 63 insertions(+), 292 deletions(-)
diff --git a/include/tscore/DynArray.h b/include/tscore/DynArray.h
deleted file mode 100644
index 49c0886..0000000
--- a/include/tscore/DynArray.h
+++ /dev/null
@@ -1,191 +0,0 @@
-/** @file
-
- Dynamic Array Implementation used by Regex.cc
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#pragma once
-
-template <class T> class DynArray
-{
-public:
- DynArray(const T *val = 0, intptr_t initial_size = 0);
- ~DynArray();
-
-#ifndef __GNUC__
- operator const T *() const;
-#endif
- operator T *();
- T &operator[](intptr_t idx);
- T &operator()(intptr_t idx);
- T *detach();
- T defvalue() const;
- intptr_t length();
- void clear();
- void set_length(intptr_t i);
-
-private:
- void resize(intptr_t new_size);
-
-private:
- T *data;
- const T *default_val;
- int size;
- int pos;
-};
-
-template <class T>
-inline DynArray<T>::DynArray(const T *val, intptr_t initial_size) :
data(nullptr), default_val(val), size(0), pos(-1)
-{
- if (initial_size > 0) {
- int i = 1;
-
- while (i < initial_size) {
- i <<= 1;
- }
-
- resize(i);
- }
-}
-
-template <class T> inline DynArray<T>::~DynArray()
-{
- if (data) {
- delete[] data;
- }
-}
-
-#ifndef __GNUC__
-template <class T> inline DynArray<T>::operator const T *() const
-{
- return data;
-}
-#endif
-
-template <class T> inline DynArray<T>::operator T *()
-{
- return data;
-}
-
-template <class T> inline T &DynArray<T>::operator[](intptr_t idx)
-{
- return data[idx];
-}
-
-template <class T>
-inline T &
-DynArray<T>::operator()(intptr_t idx)
-{
- if (idx >= size) {
- intptr_t new_size;
-
- if (size == 0) {
- new_size = 64;
- } else {
- new_size = size * 2;
- }
-
- if (idx >= new_size) {
- new_size = idx + 1;
- }
-
- resize(new_size);
- }
-
- if (idx > pos) {
- pos = idx;
- }
-
- return data[idx];
-}
-
-template <class T>
-inline T *
-DynArray<T>::detach()
-{
- T *d;
-
- d = data;
- data = nullptr;
-
- return d;
-}
-
-template <class T>
-inline T
-DynArray<T>::defvalue() const
-{
- return *default_val;
-}
-
-template <class T>
-inline intptr_t
-DynArray<T>::length()
-{
- return pos + 1;
-}
-
-template <class T>
-inline void
-DynArray<T>::clear()
-{
- if (data) {
- delete[] data;
- data = nullptr;
- }
-
- size = 0;
- pos = -1;
-}
-
-template <class T>
-inline void
-DynArray<T>::set_length(intptr_t i)
-{
- pos = i - 1;
-}
-
-template <class T>
-inline void
-DynArray<T>::resize(intptr_t new_size)
-{
- if (new_size > size) {
- T *new_data;
- intptr_t i;
-
- new_data = new T[new_size];
-
- for (i = 0; i < size; i++) {
- new_data[i] = data[i];
- }
-
- for (; i < new_size; i++) {
- if (default_val) {
- new_data[i] = (T)*default_val;
- }
- }
-
- if (data) {
- delete[] data;
- }
- data = new_data;
- size = new_size;
- }
-}
diff --git a/proxy/ControlMatcher.h b/proxy/ControlMatcher.h
index 16dc8ec..3c7c725 100644
--- a/proxy/ControlMatcher.h
+++ b/proxy/ControlMatcher.h
@@ -86,7 +86,6 @@
#pragma once
-#include "tscore/DynArray.h"
#include "tscore/IpMap.h"
#include "tscore/Result.h"
#include "tscore/MatcherUtils.h"
diff --git a/proxy/RegressionSM.cc b/proxy/RegressionSM.cc
index b31368e..ac83a69 100644
--- a/proxy/RegressionSM.cc
+++ b/proxy/RegressionSM.cc
@@ -120,16 +120,15 @@ r_sequential(RegressionTest *t, RegressionSM *sm, ...)
RegressionSM *new_sm = new RegressionSM(t);
va_list ap;
va_start(ap, sm);
- new_sm->parallel = false;
- new_sm->repeat = false;
- new_sm->ichild = 0;
- new_sm->nchildren = 0;
- new_sm->nwaiting = 0;
- while (nullptr != sm) {
- new_sm->children(new_sm->nchildren++) = sm;
- sm = va_arg(ap, RegressionSM *);
+ new_sm->parallel = false;
+ new_sm->repeat = false;
+ new_sm->ichild = 0;
+ new_sm->nwaiting = 0;
+ while (sm) {
+ new_sm->children.push_back(sm);
+ sm = va_arg(ap, RegressionSM *);
}
- new_sm->n = new_sm->nchildren;
+ new_sm->n = new_sm->children.size();
va_end(ap);
return new_sm;
}
@@ -141,10 +140,9 @@ r_sequential(RegressionTest *t, int an, RegressionSM *sm)
new_sm->parallel = false;
new_sm->repeat = true;
new_sm->ichild = 0;
- new_sm->nchildren = 1;
- new_sm->children(0) = sm;
- new_sm->nwaiting = 0;
- new_sm->n = an;
+ new_sm->children.push_back(sm);
+ new_sm->nwaiting = 0;
+ new_sm->n = an;
return new_sm;
}
@@ -154,16 +152,15 @@ r_parallel(RegressionTest *t, RegressionSM *sm, ...)
RegressionSM *new_sm = new RegressionSM(t);
va_list ap;
va_start(ap, sm);
- new_sm->parallel = true;
- new_sm->repeat = false;
- new_sm->ichild = 0;
- new_sm->nchildren = 0;
- new_sm->nwaiting = 0;
+ new_sm->parallel = true;
+ new_sm->repeat = false;
+ new_sm->ichild = 0;
+ new_sm->nwaiting = 0;
while (sm) {
- new_sm->children(new_sm->nchildren++) = sm;
- sm = va_arg(ap, RegressionSM *);
+ new_sm->children.push_back(sm);
+ sm = va_arg(ap, RegressionSM *);
}
- new_sm->n = new_sm->nchildren;
+ new_sm->n = new_sm->children.size();
va_end(ap);
return new_sm;
}
@@ -175,10 +172,9 @@ r_parallel(RegressionTest *t, int an, RegressionSM *sm)
new_sm->parallel = true;
new_sm->repeat = true;
new_sm->ichild = 0;
- new_sm->nchildren = 1;
- new_sm->children(0) = sm;
- new_sm->nwaiting = 0;
- new_sm->n = an;
+ new_sm->children.push_back(sm);
+ new_sm->nwaiting = 0;
+ new_sm->n = an;
return new_sm;
}
@@ -227,15 +223,14 @@ RegressionSM::RegressionSM(const RegressionSM &ao) :
Continuation(ao)
{
RegressionSM &o = *(RegressionSM *)&ao;
- t = o.t;
- status = o.status;
- pstatus = o.pstatus;
- parent = &o;
- nwaiting = o.nwaiting;
- nchildren = o.nchildren;
+ t = o.t;
+ status = o.status;
+ pstatus = o.pstatus;
+ parent = &o;
+ nwaiting = o.nwaiting;
- for (intptr_t i = 0; i < nchildren; i++) {
- children(i) = o.children[i]->clone();
+ for (unsigned i = 0; i < o.children.size(); i++) {
+ children.push_back(o.children[i]->clone());
}
n = o.n;
diff --git a/proxy/RegressionSM.h b/proxy/RegressionSM.h
index d643de3..31cabf8 100644
--- a/proxy/RegressionSM.h
+++ b/proxy/RegressionSM.h
@@ -25,7 +25,6 @@
#include "I_EventSystem.h"
#include "tscore/Regression.h"
-#include "tscore/DynArray.h"
/*
Regression Test Composition State Machine
@@ -50,17 +49,17 @@ struct RegressionSM : public Continuation {
void run_in(int *pstatus, ink_hrtime t);
// internal
- int status = REGRESSION_TEST_INPROGRESS;
- int *pstatus = nullptr;
- RegressionSM *parent = nullptr;
- int nwaiting = 0;
- int nchildren = 0;
- DynArray<RegressionSM *> children = nullptr;
- intptr_t n = 0;
- intptr_t ichild = 0;
- bool parallel = false;
- bool repeat = false;
- Action *pending_action = nullptr;
+ int status = REGRESSION_TEST_INPROGRESS;
+ int *pstatus = nullptr;
+ RegressionSM *parent = nullptr;
+ int nwaiting = 0;
+ int nchildren = 0;
+ std::vector<RegressionSM *> children;
+ intptr_t n = 0;
+ intptr_t ichild = 0;
+ bool parallel = false;
+ bool repeat = false;
+ Action *pending_action = nullptr;
int regression_sm_start(int event, void *data);
int regression_sm_waiting(int event, void *data);
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 0de45b2..38fe92f 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -616,6 +616,8 @@ HdrHeap::marshal(char *buf, int len)
int ptr_xl_size = 2;
MarshalXlate static_table[2];
MarshalXlate *ptr_xlation = static_table;
+ // need to initialize it here because of those gotos
+ MarshalXlate str_xlation[HDR_BUF_RONLY_HEAPS + 1];
// Let's start by skipping over the header block
// and copying the pointer blocks to marshalled
@@ -690,7 +692,6 @@ HdrHeap::marshal(char *buf, int len)
// is too big and only copy over live strings if it is. May
// not be too much of a problem since I've prevented too much
// lost string space both in string alloc and inherit
- MarshalXlate str_xlation[HDR_BUF_RONLY_HEAPS + 1];
if (m_read_write_heap) {
char *copy_start = ((char *)m_read_write_heap.get()) + sizeof(HdrStrHeap);
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index faa8c48..c1fe0b2 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -320,6 +320,7 @@ struct MarshalXlate {
char *start;
char *end;
char *offset;
+ MarshalXlate() : start(nullptr), end(nullptr), offset(nullptr) {}
};
struct HeapCheck {
diff --git a/proxy/http/HttpPages.h b/proxy/http/HttpPages.h
index b51e45e..7b9fea2 100644
--- a/proxy/http/HttpPages.h
+++ b/proxy/http/HttpPages.h
@@ -35,7 +35,6 @@
#include "tscore/ink_platform.h"
#include "P_EventSystem.h"
-#include "tscore/DynArray.h"
#include "HTTP.h"
#include "StatPages.h"
#include "HttpSM.h"
diff --git a/src/traffic_server/CoreUtils.cc b/src/traffic_server/CoreUtils.cc
index ac628b5..eac83b0 100644
--- a/src/traffic_server/CoreUtils.cc
+++ b/src/traffic_server/CoreUtils.cc
@@ -116,7 +116,7 @@ int program_counter = 0;
bool inTable;
FILE *fp;
memTable default_memTable = {0, 0, 0};
-DynArray<struct memTable> arrayMem(&default_memTable, 0);
+std::vector<struct memTable> arrayMem(0, default_memTable);
HTTPHdrImpl *global_http;
HttpSM *last_seen_http_sm = nullptr;
@@ -172,39 +172,11 @@ CoreUtils::insert_table(intptr_t vaddr1, intptr_t
offset1, intptr_t fsize1)
m.fsize = fsize1;
#endif
- if (arrayMem.length() == 0) {
- arrayMem(0);
- arrayMem[(intptr_t)0].vaddr = vaddr1;
- arrayMem[(intptr_t)0].offset = offset1;
- arrayMem[(intptr_t)0].fsize = fsize1;
+ if (arrayMem.empty()) {
+ arrayMem.push_back({vaddr1, offset1, fsize1});
} else {
- intptr_t index = find_vaddr(vaddr1, arrayMem.length(), 0);
- if (index == arrayMem.length()) {
- arrayMem(index);
- arrayMem[index].vaddr = vaddr1;
- arrayMem[index].offset = offset1;
- arrayMem[index].fsize = fsize1;
- } else if (index == 0) {
- arrayMem(arrayMem.length());
- for (intptr_t i = 0; i < arrayMem.length(); i++) {
- arrayMem[arrayMem.length() - i - 1].vaddr =
arrayMem[arrayMem.length() - i - 2].vaddr;
- arrayMem[arrayMem.length() - i - 1].offset =
arrayMem[arrayMem.length() - i - 2].offset;
- arrayMem[arrayMem.length() - i - 1].fsize =
arrayMem[arrayMem.length() - i - 2].fsize;
- }
- arrayMem[(intptr_t)0].vaddr = vaddr1;
- arrayMem[(intptr_t)0].offset = offset1;
- arrayMem[(intptr_t)0].fsize = fsize1;
- } else {
- arrayMem(arrayMem.length());
- for (intptr_t i = 1; i < arrayMem.length() - index; i++) {
- arrayMem[arrayMem.length() - i].vaddr = arrayMem[arrayMem.length() -
i - 1].vaddr;
- arrayMem[arrayMem.length() - i].offset = arrayMem[arrayMem.length() -
i - 1].offset;
- arrayMem[arrayMem.length() - i].fsize = arrayMem[arrayMem.length() -
i - 1].fsize;
- }
- arrayMem[index].vaddr = vaddr1;
- arrayMem[index].offset = offset1;
- arrayMem[index].fsize = fsize1;
- }
+ unsigned index = find_vaddr(vaddr1, arrayMem.size(), 0);
+ arrayMem.insert(arrayMem.begin() + index, {vaddr1, offset1, fsize1});
}
}
@@ -213,7 +185,7 @@ CoreUtils::insert_table(intptr_t vaddr1, intptr_t offset1,
intptr_t fsize1)
intptr_t
CoreUtils::read_from_core(intptr_t vaddr, intptr_t bytes, char *buf)
{
- intptr_t index = find_vaddr(vaddr, arrayMem.length(), 0);
+ intptr_t index = find_vaddr(vaddr, arrayMem.size(), 0);
intptr_t vadd = arrayMem[index - 1].vaddr;
intptr_t offset = arrayMem[index - 1].offset;
intptr_t size = arrayMem[index - 1].fsize;
@@ -253,7 +225,7 @@ void
CoreUtils::get_base_frame(intptr_t framep, core_stack_state *coress)
{
// finds vaddress less than framep
- intptr_t index = find_vaddr(framep, arrayMem.length(), 0);
+ intptr_t index = find_vaddr(framep, arrayMem.size(), 0);
intptr_t vadd = arrayMem[index - 1].vaddr;
intptr_t off = arrayMem[index - 1].offset;
intptr_t off2 = std::abs(vadd - framep);
@@ -294,7 +266,7 @@ CoreUtils::get_next_frame(core_stack_state *coress)
intptr_t i = 0;
intptr_t framep = coress->framep;
- intptr_t index = find_vaddr(framep, arrayMem.length(), 0);
+ intptr_t index = find_vaddr(framep, arrayMem.size(), 0);
// finds vaddress less than framep
intptr_t vadd = arrayMem[index - 1].vaddr;
@@ -490,16 +462,14 @@ CoreUtils::load_http_hdr(HTTPHdr *core_hdr, HTTPHdr
*live_hdr)
{
char buf[sizeof(char) * sizeof(HdrHeap)];
// Load HdrHeap chain
- HTTPHdr *http_hdr = core_hdr;
- HdrHeap *heap = (HdrHeap *)core_hdr->m_heap;
- HdrHeap *heap_ptr = (HdrHeap *)http_hdr->m_heap;
- intptr_t ptr_heaps = 0;
- intptr_t ptr_heap_size = 0;
- intptr_t ptr_xl_size = 2;
- intptr_t str_size = 0;
- intptr_t str_heaps = 0;
- MarshalXlate default_MarshalXlate = {nullptr, nullptr, nullptr};
- DynArray<struct MarshalXlate> ptr_xlation(&default_MarshalXlate, 2);
+ HTTPHdr *http_hdr = core_hdr;
+ HdrHeap *heap = (HdrHeap *)core_hdr->m_heap;
+ HdrHeap *heap_ptr = (HdrHeap *)http_hdr->m_heap;
+ intptr_t ptr_heaps = 0;
+ intptr_t ptr_heap_size = 0;
+ intptr_t str_size = 0;
+ intptr_t str_heaps = 0;
+ std::vector<struct MarshalXlate> ptr_xlation(2);
// MarshalXlate static_table[2];
// MarshalXlate* ptr_xlation = static_table;
intptr_t used;
@@ -537,8 +507,8 @@ CoreUtils::load_http_hdr(HTTPHdr *core_hdr, HTTPHdr
*live_hdr)
::exit(0);
}
// Expand ptr xlation table if necessary
- if (ptr_heaps >= ptr_xl_size) {
- ptr_xlation(ptr_heaps);
+ if (static_cast<unsigned>(ptr_heaps) >= ptr_xlation.size()) {
+ ptr_xlation.resize(ptr_heaps + 1);
}
char *data, *free, *off;
@@ -647,18 +617,18 @@ CoreUtils::load_http_hdr(HTTPHdr *core_hdr, HTTPHdr
*live_hdr)
}
break;
case HDR_HEAP_OBJ_HTTP_HEADER:
- if (((HTTPHdrImpl *)obj)->marshal(ptr_xlation, ptr_heaps, str_xlation,
str_heaps) < 0) {
+ if (((HTTPHdrImpl *)obj)->marshal(&ptr_xlation[0], ptr_heaps,
str_xlation, str_heaps) < 0) {
goto Failed;
}
live_hdr->m_http = (HTTPHdrImpl *)obj;
break;
case HDR_HEAP_OBJ_FIELD_BLOCK:
- if (((MIMEFieldBlockImpl *)obj)->marshal(ptr_xlation, ptr_heaps,
str_xlation, str_heaps) < 0) {
+ if (((MIMEFieldBlockImpl *)obj)->marshal(&ptr_xlation[0], ptr_heaps,
str_xlation, str_heaps) < 0) {
goto Failed;
}
break;
case HDR_HEAP_OBJ_MIME_HEADER:
- if (((MIMEHdrImpl *)obj)->marshal(ptr_xlation, ptr_heaps, str_xlation,
str_heaps)) {
+ if (((MIMEHdrImpl *)obj)->marshal(&ptr_xlation[0], ptr_heaps,
str_xlation, str_heaps)) {
goto Failed;
}
break;
diff --git a/src/traffic_server/CoreUtils.h b/src/traffic_server/CoreUtils.h
index f481729..e3e7750 100644
--- a/src/traffic_server/CoreUtils.h
+++ b/src/traffic_server/CoreUtils.h
@@ -38,7 +38,6 @@
#include <cstring>
#include <cassert>
#include <elf.h>
-#include "tscore/DynArray.h"
#define SP_REGNUM 15 /* Contains address of top of stack USP */
#define PC_REGNUM 12 /* Contains program counter EIP */
diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index 367cf8e..8c3c9f9 100644
--- a/src/tscore/Makefile.am
+++ b/src/tscore/Makefile.am
@@ -70,7 +70,6 @@ libtscore_la_SOURCES = \
defalloc.h \
Diags.cc \
Diags.h \
- DynArray.h \
EventNotify.cc \
EventNotify.h \
Extendible.h \