[PATCH] D107308: [scudo] Make Vector() constexpr
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 3 08:25:56 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG23a94af44939: [scudo] Make Vector() constexpr (authored by cryptoad).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107308/new/
https://reviews.llvm.org/D107308
Files:
compiler-rt/lib/scudo/standalone/vector.h
Index: compiler-rt/lib/scudo/standalone/vector.h
===================================================================
--- compiler-rt/lib/scudo/standalone/vector.h
+++ compiler-rt/lib/scudo/standalone/vector.h
@@ -19,13 +19,14 @@
// small vectors. The current implementation supports only POD types.
template <typename T> class VectorNoCtor {
public:
- void init(uptr InitialCapacity = 0) {
- Data = reinterpret_cast<T *>(&LocalData[0]);
+ constexpr void init(uptr InitialCapacity = 0) {
+ Data = &LocalData[0];
CapacityBytes = sizeof(LocalData);
- reserve(InitialCapacity);
+ if (InitialCapacity > capacity())
+ reserve(InitialCapacity);
}
void destroy() {
- if (Data != reinterpret_cast<T *>(&LocalData[0]))
+ if (Data != &LocalData[0])
unmap(Data, CapacityBytes);
}
T &operator[](uptr I) {
@@ -55,7 +56,7 @@
uptr size() const { return Size; }
const T *data() const { return Data; }
T *data() { return Data; }
- uptr capacity() const { return CapacityBytes / sizeof(T); }
+ constexpr uptr capacity() const { return CapacityBytes / sizeof(T); }
void reserve(uptr NewSize) {
// Never downsize internal buffer.
if (NewSize > capacity())
@@ -91,14 +92,14 @@
}
T *Data = nullptr;
- u8 LocalData[256] = {};
+ T LocalData[256 / sizeof(T)] = {};
uptr CapacityBytes = 0;
uptr Size = 0;
};
template <typename T> class Vector : public VectorNoCtor<T> {
public:
- Vector() { VectorNoCtor<T>::init(); }
+ constexpr Vector() { VectorNoCtor<T>::init(); }
explicit Vector(uptr Count) {
VectorNoCtor<T>::init(Count);
this->resize(Count);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107308.363754.patch
Type: text/x-patch
Size: 1634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210803/1192d935/attachment.bin>
More information about the llvm-commits
mailing list