Skip to content

Commit

Permalink
Bug 1268754 - Tweak some MFBT return values. r=Ms2ger.
Browse files Browse the repository at this point in the history
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).

--HG--
extra : rebase_source : 1547cdeb9ee71d0ecec608ab474ab5e75bfc4b42
  • Loading branch information
nnethercote committed Apr 29, 2016
1 parent 9c703c1 commit d8dc169
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mfbt/AllocPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MallocAllocPolicy
{
}

bool checkSimulatedOOM() const
MOZ_MUST_USE bool checkSimulatedOOM() const
{
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions mfbt/Compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class LZ4

/**
* 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.
Expand All @@ -71,9 +70,9 @@ class LZ4
* 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);

/**
Expand All @@ -91,8 +90,9 @@ class LZ4
* 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);

Expand Down
13 changes: 7 additions & 6 deletions mfbt/SplayTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ class SplayTree
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);
Expand Down Expand Up @@ -194,7 +194,7 @@ class SplayTree
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!");

Expand All @@ -204,7 +204,6 @@ class SplayTree
aNew->mParent = aLast;

splay(aNew);
return aNew;
}

/**
Expand Down Expand Up @@ -321,7 +320,9 @@ SplayTree<T, Comparator>::findOrInsert(const T& aValue)
return last;
}

return finishInsertion(last, cmp, new T(aValue));
T* t = new T(aValue);
finishInsertion(last, cmp, t);
return t;
}

} /* namespace mozilla */
Expand Down
4 changes: 2 additions & 2 deletions mfbt/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct VectorImpl
* 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());
Expand Down Expand Up @@ -215,7 +215,7 @@ struct VectorImpl<T, N, AP, true>
}
}

static inline bool
static inline MOZ_MUST_USE bool
growTo(Vector<T, N, AP>& aV, size_t aNewCap)
{
MOZ_ASSERT(!aV.usingInlineStorage());
Expand Down

0 comments on commit d8dc169

Please sign in to comment.