forked from M-Labs/nac3
WIP: list assignment
This commit is contained in:
parent
e62509ae67
commit
9b02e144b5
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <irrt/debug.hpp>
|
||||
#include <irrt/exception.hpp>
|
||||
#include <irrt/int_types.hpp>
|
||||
#include <irrt/slice.hpp>
|
||||
|
||||
|
@ -16,4 +18,42 @@ template <typename SizeT> struct List
|
|||
uint8_t *items;
|
||||
SizeT len;
|
||||
};
|
||||
|
||||
namespace list
|
||||
{
|
||||
template <typename SizeT> void range_assign(List<SizeT> *dst, SizeT itemsize, Range<SizeT> *range, List<SizeT> *src)
|
||||
{
|
||||
debug_assert(range->step != 0);
|
||||
SizeT assign_len = range->len();
|
||||
|
||||
if (assign_len < src->len)
|
||||
{
|
||||
// Encountered things like
|
||||
// ```
|
||||
// xs = [1, 2, 3, 4, 5]
|
||||
// xs[1:3] = [999, 1000, 1001, 1002] # Note that step has to be 1.
|
||||
// xs = [1, 999, 1000, 1001, 1002, 4, 5] # xs is longer
|
||||
// ```
|
||||
//
|
||||
// We do not support extending lists since that requires allocation.
|
||||
raise_exception(SizeT, EXN_VALUE_ERROR,
|
||||
"List assignment does not support list extension. Attempting to assign {0} item(s) into a "
|
||||
"space of {1} item(s).",
|
||||
src->len, assign_len, NO_PARAM);
|
||||
}
|
||||
|
||||
if (range->step == 1)
|
||||
{
|
||||
// Assigning into a contiguous region. Optimized with memmove.
|
||||
|
||||
uint8_t* p1 = dst->items + range->start * itemsize;
|
||||
uint8_t* p2 = dst->items + range->start * itemsize + assign_len * itemsize;
|
||||
|
||||
__builtin_memmove(cursor, src->items, assign_len * itemsize);
|
||||
cursor += range_len * itemsize;
|
||||
|
||||
__builtin_memmove(cursor, );
|
||||
}
|
||||
}
|
||||
} // namespace list
|
||||
} // namespace
|
Loading…
Reference in New Issue