Bug 1268754 - Tweak some MFBT return values. r=Ms2ger.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 29 Apr 2016 13:14:34 +1000
changeset 296207 d32e2e6900731d22163bcd2370ea8f75b634eb54
parent 296206 80ef7dc025ea4bdf9063ecdf71fc5333d21668a0
child 296208 d713d8fd468551618e9c35febf1e77be66bd0020
push id30233
push userryanvm@gmail.com
push dateThu, 05 May 2016 18:57:26 +0000
treeherdermozilla-central@0177462aac74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs1268754
milestone49.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 1268754 - Tweak some MFBT return values. r=Ms2ger. This patch: - Adds MOZ_MUST_USE to AllocPolicy::checkSimulatedOOM(). - Adds MOZ_MUST_USE to LZ4::decompress() (both variants) and fixes their comments. - Changes the return type of SplayTree::insert() from bool to void, because it always returns true and its callers don't check the return value. - Changes the return type of SplayTree::finishInsertion() from T* to void, because it makes things clearer -- it was just returning the aNew argument. - Adds MOZ_MUST_USE to a Vector::growTo() (both variants).
mfbt/AllocPolicy.h
mfbt/Compression.h
mfbt/SplayTree.h
mfbt/Vector.h
--- a/mfbt/AllocPolicy.h
+++ b/mfbt/AllocPolicy.h
@@ -116,17 +116,17 @@ public:
   {
     free(aPtr);
   }
 
   void reportAllocOverflow() const
   {
   }
 
-  bool checkSimulatedOOM() const
+  MOZ_MUST_USE bool checkSimulatedOOM() const
   {
     return true;
   }
 };
 
 } // namespace mozilla
 
 #endif /* mozilla_AllocPolicy_h */
--- a/mfbt/Compression.h
+++ b/mfbt/Compression.h
@@ -56,29 +56,28 @@ public:
    *   compression fails
    */
   static MFBT_API size_t
   compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest,
                         size_t aMaxOutputSize);
 
   /**
    * If the source stream is malformed, the function will stop decoding
-   * and return a negative result, indicating the byte position of the
-   * faulty instruction
+   * and return false.
    *
    * This function never writes outside of provided buffers, and never
    * modifies input buffer.
    *
    * Note: destination buffer must be already allocated, and its size must be a
    *       minimum of |aOutputSize| bytes.
    *
    * @param aOutputSize is the output size, therefore the original size
-   * @return the number of bytes read in the source buffer
+   * @return true on success, false on failure
    */
-  static MFBT_API bool
+  static MFBT_API MOZ_MUST_USE bool
   decompress(const char* aSource, char* aDest, size_t aOutputSize);
 
   /**
    * If the source stream is malformed, the function will stop decoding
    * and return false.
    *
    * This function never writes beyond aDest + aMaxOutputSize, and is
    * therefore protected against malicious data packets.
@@ -86,18 +85,19 @@ public:
    * Note: Destination buffer must be already allocated.  This version is
    *       slightly slower than the decompress without the aMaxOutputSize.
    *
    * @param aInputSize is the length of the input compressed data
    * @param aMaxOutputSize is the size of the destination buffer (which must be
    *   already allocated)
    * @param aOutputSize the actual number of bytes decoded in the destination
    *   buffer (necessarily <= aMaxOutputSize)
+   * @return true on success, false on failure
    */
-  static MFBT_API bool
+  static MFBT_API MOZ_MUST_USE bool
   decompress(const char* aSource, size_t aInputSize, char* aDest,
              size_t aMaxOutputSize, size_t* aOutputSize);
 
   /*
    * Provides the maximum size that LZ4 may output in a "worst case"
    * scenario (input data not compressible) primarily useful for memory
    * allocation of output buffer.
    * note : this function is limited by "int" range (2^31-1)
--- a/mfbt/SplayTree.h
+++ b/mfbt/SplayTree.h
@@ -71,29 +71,29 @@ public:
       return nullptr;
     }
 
     T* last = lookup(aValue);
     splay(last);
     return Comparator::compare(aValue, *last) == 0 ? last : nullptr;
   }
 
-  bool insert(T* aValue)
+  void insert(T* aValue)
   {
     MOZ_ASSERT(!find(*aValue), "Duplicate elements are not allowed.");
 
     if (!mRoot) {
       mRoot = aValue;
-      return true;
+      return;
     }
     T* last = lookup(*aValue);
     int cmp = Comparator::compare(*aValue, *last);
 
     finishInsertion(last, cmp, aValue);
-    return true;
+    return;
   }
 
   T* findOrInsert(const T& aValue);
 
   T* remove(const T& aValue)
   {
     T* last = lookup(aValue);
     MOZ_ASSERT(last, "This tree must contain the element being removed.");
@@ -189,27 +189,26 @@ private:
         node = node->mLeft;
       } else {
         node = node->mRight;
       }
     } while (node);
     return parent;
   }
 
-  T* finishInsertion(T* aLast, int32_t aCmp, T* aNew)
+  void finishInsertion(T* aLast, int32_t aCmp, T* aNew)
   {
     MOZ_ASSERT(aCmp, "Nodes shouldn't be equal!");
 
     T** parentPointer = (aCmp < 0) ? &aLast->mLeft : &aLast->mRight;
     MOZ_ASSERT(!*parentPointer);
     *parentPointer = aNew;
     aNew->mParent = aLast;
 
     splay(aNew);
-    return aNew;
   }
 
   /**
    * Rotate the tree until |node| is at the root of the tree. Performing
    * the rotations in this fashion preserves the amortized balancing of
    * the tree.
    */
   void splay(T* aNode)
@@ -316,14 +315,16 @@ SplayTree<T, Comparator>::findOrInsert(c
   }
 
   T* last = lookup(aValue);
   int cmp = Comparator::compare(aValue, *last);
   if (!cmp) {
     return last;
   }
 
-  return finishInsertion(last, cmp, new T(aValue));
+  T* t = new T(aValue);
+  finishInsertion(last, cmp, t);
+  return t;
 }
 
 }  /* namespace mozilla */
 
 #endif /* mozilla_SplayTree_h */
--- a/mfbt/Vector.h
+++ b/mfbt/Vector.h
@@ -123,17 +123,17 @@ struct VectorImpl
   }
 
   /*
    * Grows the given buffer to have capacity aNewCap, preserving the objects
    * constructed in the range [begin, end) and updating aV. Assumes that (1)
    * aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will
    * not overflow.
    */
-  static inline bool
+  static inline MOZ_MUST_USE bool
   growTo(Vector<T, N, AP>& aV, size_t aNewCap)
   {
     MOZ_ASSERT(!aV.usingInlineStorage());
     MOZ_ASSERT(!CapacityHasExcessSpace<T>(aNewCap));
     T* newbuf = aV.template pod_malloc<T>(aNewCap);
     if (MOZ_UNLIKELY(!newbuf)) {
       return false;
     }
@@ -210,17 +210,17 @@ struct VectorImpl<T, N, AP, true>
 
   static inline void copyConstructN(T* aDst, size_t aN, const T& aT)
   {
     for (T* end = aDst + aN; aDst < end; ++aDst) {
       new_(aDst, aT);
     }
   }
 
-  static inline bool
+  static inline MOZ_MUST_USE bool
   growTo(Vector<T, N, AP>& aV, size_t aNewCap)
   {
     MOZ_ASSERT(!aV.usingInlineStorage());
     MOZ_ASSERT(!CapacityHasExcessSpace<T>(aNewCap));
     T* newbuf = aV.template pod_realloc<T>(aV.mBegin, aV.mCapacity, aNewCap);
     if (MOZ_UNLIKELY(!newbuf)) {
       return false;
     }