diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-10-08 08:17:47 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-10-08 08:17:47 +0200 |
commit | 8a63a2f4175112d96a49a9ad5882839da254b747 (patch) | |
tree | 202c782f572410c47c4ca1f23c68eda613d47c96 /xpcom/glue | |
parent | 24fb2aaa359cb4abf1248996758672d701db5e24 (diff) | |
parent | a844a9b08c661217c2bc14e424cdd70b5a42e681 (diff) | |
download | UXP-8a63a2f4175112d96a49a9ad5882839da254b747.tar UXP-8a63a2f4175112d96a49a9ad5882839da254b747.tar.gz UXP-8a63a2f4175112d96a49a9ad5882839da254b747.tar.lz UXP-8a63a2f4175112d96a49a9ad5882839da254b747.tar.xz UXP-8a63a2f4175112d96a49a9ad5882839da254b747.zip |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP
Diffstat (limited to 'xpcom/glue')
-rw-r--r-- | xpcom/glue/nsTArray.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index ca74a41f7..c86772a8e 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -19,6 +19,7 @@ #include "mozilla/Move.h" #include "mozilla/ReverseIterator.h" #include "mozilla/TypeTraits.h" +#include "mozilla/Span.h" #include <string.h> @@ -1112,6 +1113,18 @@ public: const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } const_reverse_iterator crend() const { return rend(); } + // Span integration + + operator mozilla::Span<elem_type>() + { + return mozilla::Span<elem_type>(Elements(), Length()); + } + + operator mozilla::Span<const elem_type>() const + { + return mozilla::Span<const elem_type>(Elements(), Length()); + } + // // Search methods // @@ -1336,6 +1349,16 @@ protected: return ReplaceElementsAt<Item, ActualAlloc>( aStart, aCount, aArray.Elements(), aArray.Length()); } + + template<class Item, typename ActualAlloc = Alloc> + elem_type* ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span<const Item> aSpan) + { + return ReplaceElementsAt<Item, ActualAlloc>( + aStart, aCount, aSpan.Elements(), aSpan.Length()); + } + public: template<class Item> @@ -1347,6 +1370,15 @@ public: return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount, aArray); } + template<class Item> + MOZ_MUST_USE elem_type* ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span<const Item> aSpan, + const mozilla::fallible_t&) + { + return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount, aSpan); + } + // A variation on the ReplaceElementsAt method defined above. protected: template<class Item, typename ActualAlloc = Alloc> @@ -1399,6 +1431,15 @@ protected: return ReplaceElementsAt<Item, ActualAlloc>( aIndex, 0, aArray.Elements(), aArray.Length()); } + + template<class Item, typename ActualAlloc = Alloc> + elem_type* InsertElementsAt(index_type aIndex, + mozilla::Span<const Item> aSpan) + { + return ReplaceElementsAt<Item, ActualAlloc>( + aIndex, 0, aSpan.Elements(), aSpan.Length()); + } + public: template<class Item, class Allocator> @@ -1425,6 +1466,14 @@ public: return InsertElementAt<FallibleAlloc>(aIndex); } + template<class Item> + MOZ_MUST_USE elem_type* InsertElementsAt(index_type aIndex, + mozilla::Span<const Item> aSpan, + const mozilla::fallible_t&) + { + return InsertElementsAt<Item, FallibleAlloc>(aIndex, aSpan); + } + // Insert a new element, move constructing if possible. protected: template<class Item, typename ActualAlloc = Alloc> @@ -1526,6 +1575,13 @@ protected: template<class Item, typename ActualAlloc = Alloc> elem_type* AppendElements(const Item* aArray, size_type aArrayLen); + template<class Item, typename ActualAlloc = Alloc> + elem_type* AppendElements(mozilla::Span<const Item> aSpan) + { + return AppendElements<Item, FallibleAlloc>(aSpan.Elements(), + aSpan.Length()); + } + public: template<class Item> @@ -1536,6 +1592,15 @@ public: return AppendElements<Item, FallibleAlloc>(aArray, aArrayLen); } + template<class Item> + /* MOZ_MUST_USE */ + elem_type* AppendElements(mozilla::Span<const Item> aSpan, + const mozilla::fallible_t&) + { + return AppendElements<Item, FallibleAlloc>(aSpan.Elements(), + aSpan.Length()); + } + // A variation on the AppendElements method defined above. protected: template<class Item, class Allocator, typename ActualAlloc = Alloc> @@ -2347,6 +2412,25 @@ struct nsTArray_CopyChooser<AutoTArray<E, N>> typedef nsTArray_CopyWithConstructors<AutoTArray<E, N>> Type; }; +// Span integration +namespace mozilla { + +template<class ElementType, class TArrayAlloc> +Span<ElementType> +MakeSpan(nsTArray_Impl<ElementType, TArrayAlloc>& aTArray) +{ + return aTArray; +} + +template<class ElementType, class TArrayAlloc> +Span<const ElementType> +MakeSpan(const nsTArray_Impl<ElementType, TArrayAlloc>& aTArray) +{ + return aTArray; +} + +} // namespace mozilla + // Assert that AutoTArray doesn't have any extra padding inside. // // It's important that the data stored in this auto array takes up a multiple of |