Bug 1643289 - Make nsTPriorityQueue non-copyable and remove use of CopyableTArray. r=froydnj
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 10 Jun 2020 10:46:17 +0000
changeset 534859 a3b3ffcc8be73899c90a67489436e3381b4a0f57
parent 534858 127b5f65cf50112d4d567c4453eac946a8fcccec
child 534860 f8faae6114e00d12dcfbb3ed07b6fbd89c400944
push id118585
push usersgiesecke@mozilla.com
push dateWed, 10 Jun 2020 10:57:09 +0000
treeherderautoland@f8faae6114e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1643289
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1643289 - Make nsTPriorityQueue non-copyable and remove use of CopyableTArray. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D78248
xpcom/ds/nsTPriorityQueue.h
xpcom/tests/gtest/TestPriorityQueue.cpp
--- a/xpcom/ds/nsTPriorityQueue.h
+++ b/xpcom/ds/nsTPriorityQueue.h
@@ -27,21 +27,18 @@ class nsTPriorityQueue {
   nsTPriorityQueue() : mCompare(Compare()) {}
 
   /**
    * Constructor to allow a specific instance of a comparator object to be
    * used.
    */
   explicit nsTPriorityQueue(const Compare& aComp) : mCompare(aComp) {}
 
-  /**
-   * Copy constructor
-   */
-  nsTPriorityQueue(const nsTPriorityQueue& aOther)
-      : mElements(aOther.mElements), mCompare(aOther.mCompare) {}
+  nsTPriorityQueue(nsTPriorityQueue&&) = default;
+  nsTPriorityQueue& operator=(nsTPriorityQueue&&) = default;
 
   /**
    * @return True if the queue is empty or false otherwise.
    */
   bool IsEmpty() const { return mElements.IsEmpty(); }
 
   /**
    * @return The number of elements in the queue.
@@ -135,23 +132,29 @@ class nsTPriorityQueue {
    * Provides readonly access to the queue elements as an array. Generally this
    * should be avoided but may be needed in some situations such as when the
    * elements contained in the queue need to be enumerated for cycle-collection.
    * @return A pointer to the first element of the array.  If the array is
    * empty, then this pointer must not be dereferenced.
    */
   const T* Elements() const { return mElements.Elements(); }
 
+  nsTPriorityQueue Clone() const {
+    auto res = nsTPriorityQueue{mCompare};
+    res.mElements = mElements.Clone();
+    return res;
+  }
+
  protected:
   /**
    * Swaps the elements at the specified indices.
    */
   void Swap(size_type aIndexA, size_type aIndexB) {
     T temp = mElements[aIndexA];
     mElements[aIndexA] = mElements[aIndexB];
     mElements[aIndexB] = temp;
   }
 
-  CopyableTArray<T> mElements;
+  nsTArray<T> mElements;
   Compare mCompare;  // Comparator object
 };
 
 #endif  // NS_TPRIORITY_QUEUE_H_
--- a/xpcom/tests/gtest/TestPriorityQueue.cpp
+++ b/xpcom/tests/gtest/TestPriorityQueue.cpp
@@ -8,17 +8,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "gtest/gtest.h"
 
 template <class T, class Compare>
 void CheckPopSequence(const nsTPriorityQueue<T, Compare>& aQueue,
                       const T* aExpectedSequence,
                       const uint32_t aSequenceLength) {
-  nsTPriorityQueue<T, Compare> copy(aQueue);
+  nsTPriorityQueue<T, Compare> copy = aQueue.Clone();
 
   for (uint32_t i = 0; i < aSequenceLength; i++) {
     EXPECT_FALSE(copy.IsEmpty());
 
     T pop = copy.Pop();
     EXPECT_EQ(pop, aExpectedSequence[i]);
   }
 
@@ -47,17 +47,17 @@ TEST(PriorityQueue, Main)
   EXPECT_EQ(queue.Length(), 6u);
   EXPECT_FALSE(queue.IsEmpty());
   int expected[] = {2, 4, 6, 6, 8, 10};
   CheckPopSequence(queue, expected, sizeof(expected) / sizeof(expected[0]));
 
   // copy ctor is tested by using CheckPopSequence, but check default assignment
   // operator
   nsTPriorityQueue<int> queue2;
-  queue2 = queue;
+  queue2 = queue.Clone();
   CheckPopSequence(queue2, expected, sizeof(expected) / sizeof(expected[0]));
 
   queue.Clear();
   EXPECT_TRUE(queue.IsEmpty());
 
   // try same sequence with a max heap
   nsTPriorityQueue<int, MaxCompare<int> > max_queue;
   max_queue.Push(8);