mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:17:45 +00:00
AK: Moved TypedTransfer into it's own header.
This commit is contained in:
parent
678bbd29ca
commit
910924f559
3 changed files with 148 additions and 43 deletions
44
AK/Vector.h
44
AK/Vector.h
|
@ -33,6 +33,7 @@
|
|||
#include <AK/Span.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/TypedTransfer.h>
|
||||
#include <AK/kmalloc.h>
|
||||
|
||||
// NOTE: We can't include <initializer_list> during the toolchain bootstrap,
|
||||
|
@ -48,49 +49,6 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class TypedTransfer {
|
||||
public:
|
||||
static void move(T* destination, T* source, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
return;
|
||||
if constexpr (Traits<T>::is_trivial()) {
|
||||
__builtin_memmove(destination, source, count * sizeof(T));
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
new (&destination[i]) T(AK::move(source[i]));
|
||||
}
|
||||
|
||||
static void copy(T* destination, const T* source, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
return;
|
||||
if constexpr (Traits<T>::is_trivial()) {
|
||||
__builtin_memmove(destination, source, count * sizeof(T));
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
new (&destination[i]) T(source[i]);
|
||||
}
|
||||
|
||||
static bool compare(const T* a, const T* b, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
return true;
|
||||
|
||||
if constexpr (Traits<T>::is_trivial())
|
||||
return !__builtin_memcmp(a, b, count * sizeof(T));
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
if (a[i] != b[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, size_t inline_capacity>
|
||||
class Vector {
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue