Skip to content

Commit c75ad34

Browse files
committedDec 29, 2024·
ArrayInserter
1 parent 4bd106e commit c75ad34

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed
 

‎include/momo/Array.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class Array
474474
};
475475

476476
typedef internal::ArrayItemHandler<ItemTraits> ItemHandler;
477-
typedef internal::ArrayShifter<Array> ArrayShifter;
477+
typedef internal::ArrayInserter<Array> ArrayInserter;
478478
typedef typename internal::ArrayIteratorSelector<Array> IteratorSelector;
479479

480480
typedef internal::UIntMath<> SMath;
@@ -831,7 +831,7 @@ class Array
831831
if (grow || (index <= itemIndex && itemIndex < initCount))
832832
BaseArray::InsertVar(index, std::move(item));
833833
else
834-
ArrayShifter::InsertNogrow(*this, index, std::move(item));
834+
ArrayInserter::InsertNogrow(*this, index, std::move(item));
835835
}
836836

837837
void Insert(size_t index, const Item& item)
@@ -852,11 +852,11 @@ class Array
852852
ItemHandler itemHandler(memManager, FastMovableFunctor(ItemCreator(memManager, item)));
853853
if (grow)
854854
pvGrow(newCount, ArrayGrowCause::add);
855-
ArrayShifter::InsertNogrow(*this, index, count, itemHandler.Get());
855+
ArrayInserter::InsertNogrow(*this, index, count, itemHandler.Get());
856856
}
857857
else
858858
{
859-
ArrayShifter::InsertNogrow(*this, index, count, item);
859+
ArrayInserter::InsertNogrow(*this, index, count, item);
860860
}
861861
}
862862

@@ -870,11 +870,11 @@ class Array
870870
size_t newCount = GetCount() + count;
871871
if (newCount > GetCapacity())
872872
pvGrow(newCount, ArrayGrowCause::add);
873-
ArrayShifter::InsertNogrow(*this, index, begin, count);
873+
ArrayInserter::InsertNogrow(*this, index, begin, count);
874874
}
875875
else
876876
{
877-
ArrayShifter::Insert(*this, index, std::move(begin), std::move(end));
877+
BaseArray::Insert(index, std::move(begin), std::move(end));
878878
}
879879
}
880880

@@ -1038,7 +1038,7 @@ class Array
10381038
size_t newCount = GetCount() + 1;
10391039
if (newCount > GetCapacity())
10401040
pvGrow(newCount, ArrayGrowCause::add);
1041-
ArrayShifter::InsertNogrow(*this, index, std::move(itemHandler.Get()));
1041+
ArrayInserter::InsertNogrow(*this, index, std::move(itemHandler.Get()));
10421042
}
10431043

10441044
void pvRemoveBack(size_t count) noexcept

‎include/momo/ArrayUtility.h

+13-18
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace internal
158158
};
159159

160160
template<typename TArray>
161-
class ArrayShifter
161+
class ArrayInserter
162162
{
163163
public:
164164
typedef TArray Array;
@@ -196,17 +196,6 @@ namespace internal
196196
}
197197
}
198198

199-
template<std::input_iterator ArgIterator, internal::conceptSentinel<ArgIterator> ArgSentinel>
200-
static void Insert(Array& array, size_t index, ArgIterator begin, ArgSentinel end)
201-
{
202-
typedef typename ItemTraits::template Creator<
203-
std::iter_reference_t<ArgIterator>> IterCreator;
204-
MemManager& memManager = array.GetMemManager();
205-
size_t count = 0;
206-
for (ArgIterator iter = std::move(begin); iter != end; (void)++iter, ++count)
207-
array.InsertCrt(index + count, IterCreator(memManager, *iter));
208-
}
209-
210199
template<internal::conceptForwardIterator ArgIterator>
211200
static void InsertNogrow(Array& array, size_t index, ArgIterator begin, size_t count)
212201
{
@@ -259,6 +248,9 @@ namespace internal
259248
private:
260249
typedef ArrayItemHandler<ItemTraits> ItemHandler;
261250

251+
template<typename ArrayArg>
252+
using ArrayInserter = internal::ArrayInserter<std::decay_t<ArrayArg>>;
253+
262254
public:
263255
template<conceptMutableThisArg ArrayArg, conceptObjectCreator<Item> ItemCreator>
264256
void InsertCrt(this ArrayArg&& array, size_t index, ItemCreator itemCreator)
@@ -290,28 +282,31 @@ namespace internal
290282
template<conceptMutableThisArg ArrayArg>
291283
void Insert(this ArrayArg&& array, size_t index, size_t count, const Item& item)
292284
{
293-
typedef ArrayShifter<std::decay_t<ArrayArg>> ArrayShifter;
294285
typedef typename ItemTraits::template Creator<const Item&> ItemCreator;
295286
MemManager& memManager = array.GetMemManager();
296287
ItemHandler itemHandler(memManager, FastMovableFunctor(ItemCreator(memManager, item)));
297288
array.Reserve(array.GetCount() + count);
298-
ArrayShifter::InsertNogrow(array, index, count, itemHandler.Get());
289+
ArrayInserter<ArrayArg>::InsertNogrow(array, index, count, itemHandler.Get());
299290
}
300291

301292
template<conceptMutableThisArg ArrayArg,
302293
std::input_iterator ArgIterator, conceptSentinel<ArgIterator> ArgSentinel>
303294
void Insert(this ArrayArg&& array, size_t index, ArgIterator begin, ArgSentinel end)
304295
{
305-
typedef ArrayShifter<std::decay_t<ArrayArg>> ArrayShifter;
306296
if constexpr (conceptForwardIterator<ArgIterator>)
307297
{
308298
size_t count = UIntMath<>::Dist(begin, end);
309299
array.Reserve(array.GetCount() + count);
310-
ArrayShifter::InsertNogrow(array, index, begin, count);
300+
ArrayInserter<ArrayArg>::InsertNogrow(array, index, begin, count);
311301
}
312302
else
313303
{
314-
ArrayShifter::Insert(array, index, std::move(begin), std::move(end));
304+
typedef typename ItemTraits::template Creator<
305+
std::iter_reference_t<ArgIterator>> IterCreator;
306+
MemManager& memManager = array.GetMemManager();
307+
size_t count = 0;
308+
for (ArgIterator iter = std::move(begin); iter != end; (void)++iter, ++count)
309+
array.InsertCrt(index + count, IterCreator(memManager, *iter));
315310
}
316311
}
317312

@@ -381,7 +376,7 @@ namespace internal
381376
{
382377
ItemHandler itemHandler(array.GetMemManager(), std::move(itemCreator));
383378
array.Reserve(array.GetCount() + 1);
384-
ArrayShifter<Array>::InsertNogrow(array, index, std::move(itemHandler.Get()));
379+
ArrayInserter<Array>::InsertNogrow(array, index, std::move(itemHandler.Get()));
385380
}
386381
};
387382

0 commit comments

Comments
 (0)
Please sign in to comment.