-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: No longer store capacity+allocator/memory_begin in ElementLocator
- Loading branch information
Showing
10 changed files
with
249 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> | ||
<Type Name="cntgs::detail::UnmanagedVector<*>"> | ||
<DisplayString>{{ size={size_} }}</DisplayString> | ||
<Expand> | ||
<ArrayItems> | ||
<Size>size_</Size> | ||
<ValuePointer>data_</ValuePointer> | ||
</ArrayItems> | ||
</Expand> | ||
</Type> | ||
</AutoVisualizer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2024 Dennis Hezel | ||
|
||
#ifndef CNTGS_DETAIL_UNMANAGEDVECTOR_HPP | ||
#define CNTGS_DETAIL_UNMANAGEDVECTOR_HPP | ||
|
||
#include "cntgs/detail/memory.hpp" | ||
|
||
#include <cstddef> | ||
#include <cstring> | ||
|
||
namespace cntgs::detail | ||
{ | ||
template <class T> | ||
class UnmanagedVector | ||
{ | ||
private: | ||
T* data_{}; | ||
std::size_t size_{}; | ||
|
||
public: | ||
UnmanagedVector() = default; | ||
|
||
UnmanagedVector(const UnmanagedVector& other) = delete; | ||
|
||
constexpr UnmanagedVector(UnmanagedVector&& other) noexcept | ||
: data_(std::exchange(other.data_, nullptr)), size_(std::exchange(other.size_, 0)) | ||
{ | ||
} | ||
|
||
UnmanagedVector& operator=(const UnmanagedVector& other) = delete; | ||
|
||
constexpr UnmanagedVector& operator=(UnmanagedVector&& other) noexcept | ||
{ | ||
data_ = std::exchange(other.data_, nullptr); | ||
size_ = std::exchange(other.size_, 0); | ||
return *this; | ||
} | ||
|
||
[[nodiscard]] constexpr bool empty() const noexcept { return size_ == 0; } | ||
|
||
[[nodiscard]] constexpr std::size_t size() const noexcept { return size_; } | ||
|
||
[[nodiscard]] constexpr T* data() const noexcept { return data_; } | ||
|
||
[[nodiscard]] constexpr T* begin() const noexcept { return data_; } | ||
|
||
[[nodiscard]] constexpr T* end() const noexcept { return data_ + size_; } | ||
|
||
[[nodiscard]] constexpr T& operator[](std::size_t i) const noexcept { return data_[i]; } | ||
|
||
constexpr void resize_from_capacity(std::size_t new_size) noexcept { size_ = new_size; } | ||
|
||
constexpr void put_back(T&& value) noexcept | ||
{ | ||
data_[size_] = std::move(value); | ||
++size_; | ||
} | ||
|
||
template <class Allocator> | ||
constexpr void reserve(std::size_t capacity, const Allocator& allocator) | ||
{ | ||
using Traits = RebindTraits<Allocator, T>; | ||
typename Traits::allocator_type alloc(allocator); | ||
auto* const new_mem = Traits::allocate(alloc, capacity); | ||
if (!empty()) | ||
{ | ||
std::memcpy(new_mem, data_, size_ * sizeof(T)); | ||
} | ||
data_ = new_mem; | ||
} | ||
}; | ||
} // namespace cntgs::detail | ||
|
||
#endif // CNTGS_DETAIL_UNMANAGEDVECTOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters