Skip to content

Commit

Permalink
ArrayShifter::InsertNogrow
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Oct 22, 2024
1 parent 02a9b6b commit 05a22a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions include/momo/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class Array
if (grow || (index <= itemIndex && itemIndex < initCount))
InsertVar(index, std::move(item));
else
ArrayShifter::Insert(*this, index, std::make_move_iterator(std::addressof(item)), 1);
ArrayShifter::InsertNogrow(*this, index, std::make_move_iterator(std::addressof(item)), 1);
}

void Insert(size_t index, const Item& item)
Expand All @@ -840,11 +840,11 @@ class Array
ItemHandler itemHandler(memManager, FastMovableFunctor(ItemCreator(memManager, item)));
if (grow)
pvGrow(newCount, ArrayGrowCause::add);
ArrayShifter::Insert(*this, index, count, *&itemHandler);
ArrayShifter::InsertNogrow(*this, index, count, *&itemHandler);
}
else
{
ArrayShifter::Insert(*this, index, count, item);
ArrayShifter::InsertNogrow(*this, index, count, item);
}
}

Expand All @@ -858,7 +858,7 @@ class Array
size_t newCount = GetCount() + count;
if (newCount > GetCapacity())
pvGrow(newCount, ArrayGrowCause::add);
ArrayShifter::Insert(*this, index, begin, count);
ArrayShifter::InsertNogrow(*this, index, begin, count);
}
else
{
Expand Down Expand Up @@ -1042,7 +1042,7 @@ class Array
size_t newCount = GetCount() + 1;
if (newCount > GetCapacity())
pvGrow(newCount, ArrayGrowCause::add);
ArrayShifter::Insert(*this, index, std::make_move_iterator(&itemHandler), 1);
ArrayShifter::InsertNogrow(*this, index, std::make_move_iterator(&itemHandler), 1);
}

void pvRemoveBack(size_t count) noexcept
Expand Down
9 changes: 5 additions & 4 deletions include/momo/ArrayUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace internal
typedef typename Array::Settings Settings;

public:
static void Insert(Array& array, size_t index, size_t count, const Item& item)
static void InsertNogrow(Array& array, size_t index, size_t count, const Item& item)
{
size_t initCount = array.GetCount();
MOMO_CHECK(index <= initCount);
Expand Down Expand Up @@ -196,7 +196,6 @@ namespace internal
}

template<conceptInputIterator ArgIterator>
requires (!std::forward_iterator<ArgIterator>)
static void Insert(Array& array, size_t index, ArgIterator begin, ArgIterator end)
{
typedef typename ItemTraits::template Creator<
Expand All @@ -207,8 +206,10 @@ namespace internal
array.InsertCrt(index + count, IterCreator(memManager, *iter));
}

template<std::forward_iterator ArgIterator>
static void Insert(Array& array, size_t index, ArgIterator begin, size_t count)
template<conceptInputIterator ArgIterator>
requires (std::forward_iterator<ArgIterator> ||
std::is_same_v<ArgIterator, std::move_iterator<Item*>>) // vs2019, gcc12
static void InsertNogrow(Array& array, size_t index, ArgIterator begin, size_t count)
{
size_t initCount = array.GetCount();
MOMO_CHECK(index <= initCount);
Expand Down
6 changes: 3 additions & 3 deletions include/momo/MergeArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class MergeArray
MemManager& memManager = GetMemManager();
ItemHandler itemHandler(memManager, FastMovableFunctor(ItemCreator(memManager, item)));
Reserve(mCount + count);
ArrayShifter::Insert(*this, index, count, *&itemHandler);
ArrayShifter::InsertNogrow(*this, index, count, *&itemHandler);
}

template<internal::conceptInputIterator ArgIterator>
Expand All @@ -553,7 +553,7 @@ class MergeArray
{
size_t count = internal::UIntMath<>::Dist(begin, end);
Reserve(mCount + count);
ArrayShifter::Insert(*this, index, begin, count);
ArrayShifter::InsertNogrow(*this, index, begin, count);
}
else
{
Expand Down Expand Up @@ -811,7 +811,7 @@ class MergeArray
{
ItemHandler itemHandler(GetMemManager(), std::move(itemCreator));
Reserve(mCount + 1);
ArrayShifter::Insert(*this, index, std::make_move_iterator(&itemHandler), 1);
ArrayShifter::InsertNogrow(*this, index, std::make_move_iterator(&itemHandler), 1);
}

void pvRemoveBack(size_t count) noexcept
Expand Down
6 changes: 3 additions & 3 deletions include/momo/SegmentedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class SegmentedArray
MemManager& memManager = GetMemManager();
ItemHandler itemHandler(memManager, FastMovableFunctor(ItemCreator(memManager, item)));
Reserve(mCount + count);
ArrayShifter::Insert(*this, index, count, *&itemHandler);
ArrayShifter::InsertNogrow(*this, index, count, *&itemHandler);
}

template<internal::conceptInputIterator ArgIterator>
Expand All @@ -538,7 +538,7 @@ class SegmentedArray
{
size_t count = internal::UIntMath<>::Dist(begin, end);
Reserve(mCount + count);
ArrayShifter::Insert(*this, index, begin, count);
ArrayShifter::InsertNogrow(*this, index, begin, count);
}
else
{
Expand Down Expand Up @@ -678,7 +678,7 @@ class SegmentedArray
{
ItemHandler itemHandler(GetMemManager(), std::move(itemCreator));
Reserve(mCount + 1);
ArrayShifter::Insert(*this, index, std::make_move_iterator(&itemHandler), 1);
ArrayShifter::InsertNogrow(*this, index, std::make_move_iterator(&itemHandler), 1);
}

template<internal::conceptObjectMultiCreator<Item> MultiItemCreator>
Expand Down

0 comments on commit 05a22a9

Please sign in to comment.