Skip to content

[scudo] Add static vector functionality. #98986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 17, 2024
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions compiler-rt/lib/scudo/standalone/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef SCUDO_VECTOR_H_
#define SCUDO_VECTOR_H_

#include "common.h"
#include "internal_defs.h"
#include "mem_map.h"

#include <string.h>
Expand All @@ -21,7 +23,7 @@ namespace scudo {
// implementation supports only POD types.
//
// NOTE: This class is not meant to be used directly, use Vector<T> instead.
template <typename T> class VectorNoCtor {
template <typename T, size_t StaticCapacity> class VectorNoCtor {
public:
T &operator[](uptr I) {
DCHECK_LT(I, Size);
Expand Down Expand Up @@ -116,18 +118,19 @@ template <typename T> class VectorNoCtor {
uptr CapacityBytes = 0;
uptr Size = 0;

T LocalData[256 / sizeof(T)] = {};
T LocalData[StaticCapacity] = {};
MemMapT ExternalBuffer;
};

template <typename T> class Vector : public VectorNoCtor<T> {
template <typename T, size_t StaticCapacity = 8>
class Vector : public VectorNoCtor<T, Max<size_t>(1, StaticCapacity)> {
public:
constexpr Vector() { VectorNoCtor<T>::init(); }
constexpr Vector() { VectorNoCtor<T, StaticCapacity>::init(); }
explicit Vector(uptr Count) {
VectorNoCtor<T>::init(Count);
VectorNoCtor<T, StaticCapacity>::init(Count);
this->resize(Count);
}
~Vector() { VectorNoCtor<T>::destroy(); }
~Vector() { VectorNoCtor<T, StaticCapacity>::destroy(); }
// Disallow copies and moves.
Vector(const Vector &) = delete;
Vector &operator=(const Vector &) = delete;
Expand Down
Loading