Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 04c158e

Browse files
Bug 1942273 - Use std::uninitialized_copy instead of a custom algorithm r=glandium,xpcom-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D233993
1 parent 6925985 commit 04c158e

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

xpcom/ds/nsTArray.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -649,30 +649,6 @@ class nsDefaultComparator {
649649
bool LessThan(const A& aA, const B& aB) const { return aA < aB; }
650650
};
651651

652-
template <bool IsTriviallyCopyConstructible, bool IsSameType>
653-
struct AssignRangeAlgorithm {
654-
template <class Item, class ElemType, class IndexType, class SizeType>
655-
static void implementation(ElemType* aElements, IndexType aStart,
656-
SizeType aCount, const Item* aValues) {
657-
ElemType* iter = aElements + aStart;
658-
ElemType* end = iter + aCount;
659-
for (; iter != end; ++iter, ++aValues) {
660-
nsTArrayElementTraits<ElemType>::Construct(iter, *aValues);
661-
}
662-
}
663-
};
664-
665-
template <>
666-
struct AssignRangeAlgorithm<true, true> {
667-
template <class Item, class ElemType, class IndexType, class SizeType>
668-
static void implementation(ElemType* aElements, IndexType aStart,
669-
SizeType aCount, const Item* aValues) {
670-
if (aValues) {
671-
memcpy(aElements + aStart, aValues, aCount * sizeof(ElemType));
672-
}
673-
}
674-
};
675-
676652
//
677653
// Normally elements are copied with memcpy and memmove, but for some element
678654
// types that is problematic. The nsTArray_RelocationStrategy template class
@@ -2434,10 +2410,7 @@ class nsTArray_Impl
24342410
// @param aValues The array of elements to copy.
24352411
template <class Item>
24362412
void AssignRange(index_type aStart, size_type aCount, const Item* aValues) {
2437-
AssignRangeAlgorithm<
2438-
std::is_trivially_copyable_v<Item>,
2439-
std::is_same_v<Item, value_type>>::implementation(Elements(), aStart,
2440-
aCount, aValues);
2413+
std::uninitialized_copy(aValues, aValues + aCount, Elements() + aStart);
24412414
}
24422415
};
24432416

0 commit comments

Comments
 (0)