Merge pull request #3485 from sfc-gh-mpilman/cleanup/tracing-cleanup
Address review comments from tracing work
This commit is contained in:
commit
8048fea51d
104
flow/Arena.h
104
flow/Arena.h
|
@ -1010,21 +1010,21 @@ public:
|
||||||
using pointer = value_type*;
|
using pointer = value_type*;
|
||||||
using reference = value_type&;
|
using reference = value_type&;
|
||||||
friend class SmallVectorRef<T, InlineMembers>;
|
friend class SmallVectorRef<T, InlineMembers>;
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend bool operator<(const iterator_impl<I>&, const iterator_impl<I>&);
|
friend bool operator<(const iterator_impl<I>&, const iterator_impl<I>&);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend bool operator>(const iterator_impl<I>&, const iterator_impl<I>&);
|
friend bool operator>(const iterator_impl<I>&, const iterator_impl<I>&);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend bool operator<=(const iterator_impl<I>&, const iterator_impl<I>&);
|
friend bool operator<=(const iterator_impl<I>&, const iterator_impl<I>&);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend bool operator>=(const iterator_impl<I>&, const iterator_impl<I>&);
|
friend bool operator>=(const iterator_impl<I>&, const iterator_impl<I>&);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend self_t operator+(const iterator_impl<I>&, difference_type);
|
friend self_t operator+(const iterator_impl<I>&, difference_type);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend self_t operator+(difference_type, const self_t&);
|
friend self_t operator+(difference_type, const self_t&);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend self_t operator-(const iterator_impl<I>&, difference_type);
|
friend self_t operator-(const iterator_impl<I>&, difference_type);
|
||||||
template<bool I>
|
template <bool I>
|
||||||
friend difference_type operator-(iterator_impl<I>, self_t);
|
friend difference_type operator-(iterator_impl<I>, self_t);
|
||||||
|
|
||||||
self_t& operator++() {
|
self_t& operator++() {
|
||||||
|
@ -1033,7 +1033,7 @@ public:
|
||||||
}
|
}
|
||||||
self_t operator++(int) {
|
self_t operator++(int) {
|
||||||
auto res = *this;
|
auto res = *this;
|
||||||
++res;
|
++(*this);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
self_t& operator--() {
|
self_t& operator--() {
|
||||||
|
@ -1042,7 +1042,7 @@ public:
|
||||||
}
|
}
|
||||||
self_t operator--(int) {
|
self_t operator--(int) {
|
||||||
auto res = *this;
|
auto res = *this;
|
||||||
--res;
|
--(*this);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
self_t& operator+=(difference_type diff) {
|
self_t& operator+=(difference_type diff) {
|
||||||
|
@ -1076,10 +1076,9 @@ public: // Construction
|
||||||
static_assert(std::is_trivially_destructible_v<T>);
|
static_assert(std::is_trivially_destructible_v<T>);
|
||||||
SmallVectorRef() {}
|
SmallVectorRef() {}
|
||||||
SmallVectorRef(const SmallVectorRef<T, InlineMembers>& other)
|
SmallVectorRef(const SmallVectorRef<T, InlineMembers>& other)
|
||||||
: m_size(other.m_size), m_capacity(std::max(other.m_capacity, InlineMembers)), arr(other.arr), data(other.data) {}
|
: m_size(other.m_size), arr(other.arr), data(other.data) {}
|
||||||
SmallVectorRef& operator=(const SmallVectorRef<T, InlineMembers>& other) {
|
SmallVectorRef& operator=(const SmallVectorRef<T, InlineMembers>& other) {
|
||||||
m_size = other.m_size;
|
m_size = other.m_size;
|
||||||
m_capacity = other.m_capacity;
|
|
||||||
arr = other.arr;
|
arr = other.arr;
|
||||||
data = other.data;
|
data = other.data;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -1087,52 +1086,46 @@ public: // Construction
|
||||||
|
|
||||||
template <class T2 = T, int IM = InlineMembers>
|
template <class T2 = T, int IM = InlineMembers>
|
||||||
SmallVectorRef(Arena& arena, const SmallVectorRef<T, IM>& toCopy,
|
SmallVectorRef(Arena& arena, const SmallVectorRef<T, IM>& toCopy,
|
||||||
typename std::enable_if<!flow_ref<T2>::value, int>::type = 0)
|
typename std::enable_if<!flow_ref<T2>::value, int>::type = 0)
|
||||||
: m_size(toCopy.m_size), m_capacity(std::max(InlineMembers, toCopy.m_capacity)),
|
: m_size(toCopy.m_size) {
|
||||||
data(toCopy.m_size <= InlineMembers ? nullptr
|
if (toCopy.size() > InlineMembers) {
|
||||||
: (T*)new (arena) uint8_t[sizeof(T) * (toCopy.m_size - InlineMembers)]) {
|
data.resize(arena, toCopy.size() - InlineMembers);
|
||||||
|
}
|
||||||
std::copy(toCopy.cbegin(), toCopy.cend(), begin());
|
std::copy(toCopy.cbegin(), toCopy.cend(), begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T2 = T, int IM = InlineMembers>
|
template <class T2 = T, int IM = InlineMembers>
|
||||||
SmallVectorRef(Arena& arena, const SmallVectorRef<T2, IM>& toCopy,
|
SmallVectorRef(Arena& arena, const SmallVectorRef<T2, IM>& toCopy,
|
||||||
typename std::enable_if<flow_ref<T2>::value, int>::type = 0)
|
typename std::enable_if<flow_ref<T2>::value, int>::type = 0)
|
||||||
: m_size(toCopy.m_size), m_capacity(std::max(toCopy.m_capacity, InlineMembers)),
|
: m_size(toCopy.m_size) {
|
||||||
data(toCopy.m_size <= InlineMembers ? nullptr
|
for (int i = 0; i < toCopy.size(); ++i) {
|
||||||
: (T*)new (arena) uint8_t[sizeof(T) * (toCopy.m_size - InlineMembers)]) {
|
|
||||||
for (int i = 0; i < toCopy.m_size; ++i) {
|
|
||||||
if (i < arr.size()) {
|
if (i < arr.size()) {
|
||||||
new (&arr[i]) T(arena, toCopy[i]);
|
new (&arr[i]) T(arena, toCopy[i]);
|
||||||
} else {
|
} else {
|
||||||
new (&data[i - InlineMembers]) T(arena, toCopy[i]);
|
data.push_back_deep(arena, toCopy[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::copy(toCopy.cbegin(), toCopy.cend(), begin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class It>
|
template <class It>
|
||||||
SmallVectorRef(Arena& arena, It first, It last)
|
SmallVectorRef(Arena& arena, It first, It last)
|
||||||
: m_size(0), m_capacity(std::max(int(std::distance(first, last)), InlineMembers)),
|
: m_size(0) {
|
||||||
data(m_capacity <= InlineMembers ? nullptr
|
|
||||||
: (T*)new (arena) uint8_t[sizeof(T) * (m_capacity - InlineMembers)]) {
|
|
||||||
while (first != last && m_size < InlineMembers) {
|
while (first != last && m_size < InlineMembers) {
|
||||||
new (&arr[m_size++]) T(*(first++));
|
new (&arr[m_size++]) T(*(first++));
|
||||||
}
|
}
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
new (&arr[m_size++ - InlineMembers]) T(*(first++));
|
data.push_back(arena, *(first++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallVectorRef(SmallVectorRef<T, InlineMembers>&& o)
|
SmallVectorRef(SmallVectorRef<T, InlineMembers>&& o)
|
||||||
: m_size(o.m_size), m_capacity(o.m_capacity), arr(std::move(o.arr)), data(o.data) {
|
: m_size(o.m_size), arr(std::move(o.arr)), data(std::move(o.data)) {
|
||||||
o.m_size = 0;
|
o.m_size = 0;
|
||||||
o.m_capacity = InlineMembers;
|
|
||||||
o.data = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public: // information
|
public: // information
|
||||||
int size() const { return m_size; }
|
int size() const { return m_size; }
|
||||||
int capacity() const { return m_capacity; }
|
int capacity() const { return InlineMembers + data.capacity(); }
|
||||||
bool empty() const { return m_size == 0; }
|
bool empty() const { return m_size == 0; }
|
||||||
|
|
||||||
public: // element access
|
public: // element access
|
||||||
|
@ -1150,15 +1143,12 @@ public: // element access
|
||||||
|
|
||||||
public: // Modification
|
public: // Modification
|
||||||
void push_back(Arena& arena, T const& value) {
|
void push_back(Arena& arena, T const& value) {
|
||||||
UNSTOPPABLE_ASSERT(m_capacity >= m_size && m_capacity >= InlineMembers);
|
|
||||||
if (m_size < InlineMembers) {
|
if (m_size < InlineMembers) {
|
||||||
new (&arr[m_size++]) T(value);
|
new (&arr[m_size++]) T(value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_size == m_capacity) {
|
++m_size;
|
||||||
reallocate(arena, m_capacity + 1);
|
data.push_back(arena, value);
|
||||||
}
|
|
||||||
new (&data[m_size++ - InlineMembers]) T(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back_deep(Arena& arena, T const& value) {
|
void push_back_deep(Arena& arena, T const& value) {
|
||||||
|
@ -1166,13 +1156,11 @@ public: // Modification
|
||||||
new (&arr[m_size++]) T(arena, value);
|
new (&arr[m_size++]) T(arena, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_size == m_capacity) {
|
++m_size;
|
||||||
reallocate(arena, m_capacity + 1);
|
data.push_back_deep(arena, value);
|
||||||
}
|
|
||||||
new (&data[m_size++ - InlineMembers]) T(arena, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop_back() { --m_size; }
|
void pop_back() {--m_size; }
|
||||||
|
|
||||||
template <class It>
|
template <class It>
|
||||||
void append(Arena& arena, It first, It last) {
|
void append(Arena& arena, It first, It last) {
|
||||||
|
@ -1180,14 +1168,14 @@ public: // Modification
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto d = std::distance(first, last);
|
auto d = std::distance(first, last);
|
||||||
if (m_size + d < m_capacity) {
|
if (m_size + d > InlineMembers) {
|
||||||
reallocate(arena, m_capacity);
|
data.reserve(arena, m_size + d - InlineMembers);
|
||||||
}
|
}
|
||||||
while (first != last && m_size < InlineMembers) {
|
while (first != last && m_size < InlineMembers) {
|
||||||
new (&(arr[m_size++])) T(*(first++));
|
new (&(arr[m_size++])) T(*(first++));
|
||||||
}
|
}
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
new (&data[m_size++ - InlineMembers]) T(*(first++));
|
data.push_back(arena, *(first++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1197,14 +1185,14 @@ public: // Modification
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto d = std::distance(first, last);
|
auto d = std::distance(first, last);
|
||||||
if (m_size + d < m_capacity) {
|
if (m_size + d > InlineMembers) {
|
||||||
reallocate(arena, m_capacity);
|
data.reserve(arena, m_size + d - InlineMembers);
|
||||||
}
|
}
|
||||||
while (first != last && m_size < InlineMembers) {
|
while (first != last && m_size < InlineMembers) {
|
||||||
new (&(arr[m_size++])) T(arena, *(first++));
|
new (&(arr[m_size++])) T(arena, *(first++));
|
||||||
}
|
}
|
||||||
while (first != last) {
|
while (first != last) {
|
||||||
new (&data[m_size++ - InlineMembers]) T(arena, *(first++));
|
data.push_back_deep(arena, *(first++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1253,22 +1241,10 @@ public: // iterator access
|
||||||
|
|
||||||
const_reverse_iterator rend() const { return crend(); }
|
const_reverse_iterator rend() const { return crend(); }
|
||||||
|
|
||||||
private: // memory management
|
|
||||||
void reallocate(Arena& p, int requiredCapacity) {
|
|
||||||
requiredCapacity = std::max(m_capacity * 2, requiredCapacity);
|
|
||||||
// SOMEDAY: Maybe we are right at the end of the arena and can expand cheaply
|
|
||||||
T* newData = new (p) T[requiredCapacity - InlineMembers];
|
|
||||||
if (m_size > InlineMembers) {
|
|
||||||
std::move(data, data + m_size - InlineMembers, newData);
|
|
||||||
}
|
|
||||||
data = newData;
|
|
||||||
m_capacity = requiredCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_size = 0, m_capacity = InlineMembers;
|
int m_size = 0;
|
||||||
std::array<T, InlineMembers> arr;
|
std::array<T, InlineMembers> arr;
|
||||||
T* data = nullptr;
|
VectorRef<T> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T, int InlineMembers, bool isConst>
|
template <class T, int InlineMembers, bool isConst>
|
||||||
|
|
|
@ -112,7 +112,7 @@ Reference<IThreadPool> createGenericThreadPool();
|
||||||
class DummyThreadPool : public IThreadPool, ReferenceCounted<DummyThreadPool> {
|
class DummyThreadPool : public IThreadPool, ReferenceCounted<DummyThreadPool> {
|
||||||
public:
|
public:
|
||||||
~DummyThreadPool() {}
|
~DummyThreadPool() {}
|
||||||
DummyThreadPool() : thread(NULL) {}
|
DummyThreadPool() : thread(nullptr) {}
|
||||||
Future<Void> getError() {
|
Future<Void> getError() {
|
||||||
return errors.getFuture();
|
return errors.getFuture();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue