diff --git a/content/base/src/nsDOMFile.cpp b/content/base/src/nsDOMFile.cpp index ebc00568aed..8be4e363c79 100644 --- a/content/base/src/nsDOMFile.cpp +++ b/content/base/src/nsDOMFile.cpp @@ -940,7 +940,7 @@ public: } else { SHA1Sum sha1; sha1.update(owner->mData, owner->mLength); - uint8_t digest[SHA1Sum::HashSize]; // SHA1 digests are 20 bytes long. + uint8_t digest[SHA1Sum::kHashSize]; // SHA1 digests are 20 bytes long. sha1.finish(digest); nsAutoCString digestString; diff --git a/gfx/layers/LayerScope.cpp b/gfx/layers/LayerScope.cpp index 1f318101bcc..435ec716414 100644 --- a/gfx/layers/LayerScope.cpp +++ b/gfx/layers/LayerScope.cpp @@ -243,9 +243,9 @@ private: SHA1Sum sha1; nsCString combined(wsKey + guid); sha1.update(combined.get(), combined.Length()); - uint8_t digest[SHA1Sum::HashSize]; // SHA1 digests are 20 bytes long. + uint8_t digest[SHA1Sum::kHashSize]; // SHA1 digests are 20 bytes long. sha1.finish(digest); - nsCString newString(reinterpret_cast(digest), SHA1Sum::HashSize); + nsCString newString(reinterpret_cast(digest), SHA1Sum::kHashSize); Base64Encode(newString, res); nsCString response("HTTP/1.1 101 Switching Protocols\r\n"); diff --git a/js/public/HashTable.h b/js/public/HashTable.h index d2759722aae..4ef103f9e43 100644 --- a/js/public/HashTable.h +++ b/js/public/HashTable.h @@ -1016,7 +1016,7 @@ class HashTable : private AllocPolicy #endif friend class mozilla::ReentrancyGuard; - mutable mozilla::DebugOnly entered; + mutable mozilla::DebugOnly mEntered; mozilla::DebugOnly mutationCount; // The default initial capacity is 32 (enough to hold 16 elements), but it @@ -1076,7 +1076,7 @@ class HashTable : private AllocPolicy gen(0), removedCount(0), table(nullptr), - entered(false), + mEntered(false), mutationCount(0) {} @@ -1452,7 +1452,7 @@ class HashTable : private AllocPolicy void finish() { - MOZ_ASSERT(!entered); + MOZ_ASSERT(!mEntered); if (!table) return; diff --git a/js/src/gc/StoreBuffer.h b/js/src/gc/StoreBuffer.h index 64caf80f3f4..d84e5c171f0 100644 --- a/js/src/gc/StoreBuffer.h +++ b/js/src/gc/StoreBuffer.h @@ -422,14 +422,14 @@ class StoreBuffer bool aboutToOverflow_; bool enabled_; - mozilla::DebugOnly entered; /* For ReentrancyGuard. */ + mozilla::DebugOnly mEntered; /* For ReentrancyGuard. */ public: explicit StoreBuffer(JSRuntime *rt, const Nursery &nursery) : bufferVal(), bufferCell(), bufferSlot(), bufferWholeCell(), bufferRelocVal(), bufferRelocCell(), bufferGeneric(), runtime_(rt), nursery_(nursery), aboutToOverflow_(false), enabled_(false), - entered(false) + mEntered(false) { } diff --git a/mfbt/Alignment.h b/mfbt/Alignment.h index e0843cad03e..0ac8a48779b 100644 --- a/mfbt/Alignment.h +++ b/mfbt/Alignment.h @@ -64,8 +64,8 @@ template struct AlignedElem; /* - * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where - * foo is a template parameter. + * We have to specialize this template because GCC doesn't like + * __attribute__((aligned(foo))) where foo is a template parameter. */ template<> diff --git a/mfbt/ArrayUtils.h b/mfbt/ArrayUtils.h index f265a15d7aa..44f5980c44c 100644 --- a/mfbt/ArrayUtils.h +++ b/mfbt/ArrayUtils.h @@ -144,7 +144,8 @@ template inline bool IsInRange(T* aPtr, uintptr_t aBegin, uintptr_t aEnd) { - return IsInRange(aPtr, reinterpret_cast(aBegin), reinterpret_cast(aEnd)); + return IsInRange(aPtr, + reinterpret_cast(aBegin), reinterpret_cast(aEnd)); } namespace detail { diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h index 4fed200d621..a463b2768d6 100644 --- a/mfbt/Assertions.h +++ b/mfbt/Assertions.h @@ -149,7 +149,8 @@ MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) } static MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS +MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) + MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS { #ifdef ANDROID __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", @@ -254,7 +255,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {} do { \ MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ MOZ_REALLY_CRASH(); \ - } while(0) + } while (0) #endif #ifdef __cplusplus @@ -384,7 +385,7 @@ void ValidateAssertConditionType() #ifdef DEBUG # define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) #else -# define MOZ_ASSERT(...) do { } while(0) +# define MOZ_ASSERT(...) do { } while (0) #endif /* DEBUG */ /* diff --git a/mfbt/Atomics.h b/mfbt/Atomics.h index d2b571885c8..71d95c61bac 100644 --- a/mfbt/Atomics.h +++ b/mfbt/Atomics.h @@ -285,7 +285,8 @@ private: * atomic is not the same as adding X to a T*. Hence the need * for this function to provide the correct addend. */ - static ptrdiff_t fixupAddend(ptrdiff_t aVal) { + static ptrdiff_t fixupAddend(ptrdiff_t aVal) + { #if defined(__clang__) || defined(_MSC_VER) return aVal; #elif defined(__GNUC__) && MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) && \ diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index d317766ccb1..cdce8c77173 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -155,9 +155,10 @@ * template * class Ptr * { - * T* ptr; - * MOZ_EXPLICIT_CONVERSION operator bool() const { - * return ptr != nullptr; + * T* mPtr; + * MOZ_EXPLICIT_CONVERSION operator bool() const + * { + * return mPtr != nullptr; * } * }; * @@ -206,7 +207,8 @@ * function does not return. (The function definition does not need to be * annotated.) * - * MOZ_ReportCrash(const char* s, const char* file, int ln) MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS + * MOZ_ReportCrash(const char* s, const char* file, int ln) + * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS * * Some static analyzers, like scan-build from clang, can use this information * to eliminate false positives. From the upstream documentation of scan-build: @@ -447,13 +449,13 @@ * * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; * int MOZ_TYPE_ATTRIBUTE someVariable; - * int * MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt; + * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; + * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; * * Attributes that apply to statements precede the statement: * * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while(0); + * MOZ_DO_ATTRIBUTE do { } while (0); * * Attributes that apply to labels precede the label: * diff --git a/mfbt/BinarySearch.h b/mfbt/BinarySearch.h index 3e165e23c87..c8f593d6a92 100644 --- a/mfbt/BinarySearch.h +++ b/mfbt/BinarySearch.h @@ -26,8 +26,9 @@ namespace mozilla { * Vector sortedInts = ... * * size_t match; - * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) + * if (BinarySearch(sortedInts, 0, sortedInts.length(), 13, &match)) { * printf("found 13 at %lu\n", match); + * } */ template diff --git a/mfbt/Char16.h b/mfbt/Char16.h index af416690a0f..e54eb0d5c8d 100644 --- a/mfbt/Char16.h +++ b/mfbt/Char16.h @@ -107,9 +107,9 @@ public: } /** - * Some Windows API calls accept BYTE* but require that data actually be WCHAR*. - * Supporting this requires explicit operators to support the requisite explicit - * casts. + * Some Windows API calls accept BYTE* but require that data actually be + * WCHAR*. Supporting this requires explicit operators to support the + * requisite explicit casts. */ explicit operator const char*() const { @@ -121,7 +121,8 @@ public: } explicit operator unsigned char*() const { - return const_cast(reinterpret_cast(mPtr)); + return + const_cast(reinterpret_cast(mPtr)); } explicit operator void*() const { @@ -133,7 +134,7 @@ public: { return mPtr[aIndex]; } - bool operator==(const char16ptr_t &aOther) const + bool operator==(const char16ptr_t& aOther) const { return mPtr == aOther.mPtr; } @@ -141,7 +142,7 @@ public: { return mPtr == nullptr; } - bool operator!=(const char16ptr_t &aOther) const + bool operator!=(const char16ptr_t& aOther) const { return mPtr != aOther.mPtr; } @@ -153,7 +154,7 @@ public: { return char16ptr_t(mPtr + aValue); } - ptrdiff_t operator-(const char16ptr_t &aOther) const + ptrdiff_t operator-(const char16ptr_t& aOther) const { return mPtr - aOther.mPtr; } diff --git a/mfbt/CheckedInt.h b/mfbt/CheckedInt.h index e37c548eff4..ad4c5fef411 100644 --- a/mfbt/CheckedInt.h +++ b/mfbt/CheckedInt.h @@ -447,7 +447,7 @@ struct NegateImpl * (aX+aY)/aZ, that doesn't crash if aZ==0, and that reports on error (divide by * zero or integer overflow). You could code it as follows: @code - bool computeXPlusYOverZ(int aX, int aY, int aZ, int *aResult) + bool computeXPlusYOverZ(int aX, int aY, int aZ, int* aResult) { CheckedInt checkedResult = (CheckedInt(aX) + aY) / aZ; if (checkedResult.isValid()) { diff --git a/mfbt/Compression.cpp b/mfbt/Compression.cpp index b22052978b7..154cef1031a 100644 --- a/mfbt/Compression.cpp +++ b/mfbt/Compression.cpp @@ -48,7 +48,7 @@ LZ4::decompress(const char* aSource, char* aDest, size_t aOutputSize) bool LZ4::decompress(const char* aSource, size_t aInputSize, char* aDest, - size_t aMaxOutputSize, size_t *aOutputSize) + size_t aMaxOutputSize, size_t* aOutputSize) { CheckedInt maxOutputSizeChecked = aMaxOutputSize; MOZ_ASSERT(maxOutputSizeChecked.isValid()); diff --git a/mfbt/Compression.h b/mfbt/Compression.h index 8f9336752ba..a764a1b5d54 100644 --- a/mfbt/Compression.h +++ b/mfbt/Compression.h @@ -94,7 +94,7 @@ public: */ static MFBT_API bool decompress(const char* aSource, size_t aInputSize, char* aDest, - size_t aMaxOutputSize, size_t *aOutputSize); + size_t aMaxOutputSize, size_t* aOutputSize); /* * Provides the maximum size that LZ4 may output in a "worst case" diff --git a/mfbt/Endian.h b/mfbt/Endian.h index 353acd24978..e4e1ff8549a 100644 --- a/mfbt/Endian.h +++ b/mfbt/Endian.h @@ -474,7 +474,8 @@ protected: * Likewise, but converts values in place. */ template - static void swapToBigEndianInPlace(T* aPtr, size_t aCount) { + static void swapToBigEndianInPlace(T* aPtr, size_t aCount) + { maybeSwapInPlace(aPtr, aCount); } diff --git a/mfbt/FloatingPoint.cpp b/mfbt/FloatingPoint.cpp index 53960116cab..1ccae46002e 100644 --- a/mfbt/FloatingPoint.cpp +++ b/mfbt/FloatingPoint.cpp @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/mfbt/HashFunctions.cpp b/mfbt/HashFunctions.cpp index 374688998b5..3273e1788ea 100644 --- a/mfbt/HashFunctions.cpp +++ b/mfbt/HashFunctions.cpp @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/mfbt/IntegerPrintfMacros.h b/mfbt/IntegerPrintfMacros.h index d0b47454542..ff2415a86f9 100644 --- a/mfbt/IntegerPrintfMacros.h +++ b/mfbt/IntegerPrintfMacros.h @@ -1,7 +1,8 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Implements the C99 interface, minus the SCN* format macros. */ diff --git a/mfbt/IntegerTypeTraits.h b/mfbt/IntegerTypeTraits.h index 0a3853b7f3f..9414451f913 100644 --- a/mfbt/IntegerTypeTraits.h +++ b/mfbt/IntegerTypeTraits.h @@ -82,7 +82,8 @@ struct UnsignedStdintTypeForSize template struct PositionOfSignBit { - static_assert(IsIntegral::value, "PositionOfSignBit is only for integral types"); + static_assert(IsIntegral::value, + "PositionOfSignBit is only for integral types"); // 8 here should be CHAR_BIT from limits.h, but the world has moved on. static const size_t value = 8 * sizeof(IntegerType) - 1; }; @@ -96,7 +97,8 @@ template struct MinValue { private: - static_assert(IsIntegral::value, "MinValue is only for integral types"); + static_assert(IsIntegral::value, + "MinValue is only for integral types"); typedef typename MakeUnsigned::Type UnsignedIntegerType; static const size_t PosOfSignBit = PositionOfSignBit::value; @@ -122,7 +124,8 @@ public: template struct MaxValue { - static_assert(IsIntegral::value, "MaxValue is only for integral types"); + static_assert(IsIntegral::value, + "MaxValue is only for integral types"); // Tricksy, but covered by the CheckedInt unit test. // Relies on the type of MinValue::value diff --git a/mfbt/LinkedList.h b/mfbt/LinkedList.h index e428f37facd..693c019f92c 100644 --- a/mfbt/LinkedList.h +++ b/mfbt/LinkedList.h @@ -463,7 +463,8 @@ public: private: friend class LinkedListElement; - void assertContains(const T* aValue) const { + void assertContains(const T* aValue) const + { #ifdef DEBUG for (const T* elem = getFirst(); elem; elem = elem->getNext()) { if (elem == aValue) { diff --git a/mfbt/MathAlgorithms.h b/mfbt/MathAlgorithms.h index 21e0c23ebf2..cd71d197700 100644 --- a/mfbt/MathAlgorithms.h +++ b/mfbt/MathAlgorithms.h @@ -102,7 +102,8 @@ template<> struct AbsReturnTypeFixed { typedef uint64_t Type; }; template struct AbsReturnType : AbsReturnTypeFixed {}; -template<> struct AbsReturnType : EnableIf {}; +template<> struct AbsReturnType : + EnableIf {}; template<> struct AbsReturnType { typedef unsigned char Type; }; template<> struct AbsReturnType { typedef unsigned short Type; }; template<> struct AbsReturnType { typedef unsigned int Type; }; @@ -145,7 +146,8 @@ Abs(const long double aLongDouble) } // namespace mozilla -#if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +#if defined(_WIN32) && (_MSC_VER >= 1300) && \ + (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) # define MOZ_BITSCAN_WINDOWS # include diff --git a/mfbt/MaybeOneOf.h b/mfbt/MaybeOneOf.h index feae1c11e99..1c58f88253a 100644 --- a/mfbt/MaybeOneOf.h +++ b/mfbt/MaybeOneOf.h @@ -12,8 +12,7 @@ #include "mozilla/Move.h" #include "mozilla/TemplateLib.h" -// For placement new -#include +#include // For placement new namespace mozilla { @@ -35,13 +34,15 @@ class MaybeOneOf template struct Type2State {}; template - T& as() { + T& as() + { MOZ_ASSERT(state == Type2State::result); return *(T*)storage.addr(); } template - const T& as() const { + const T& as() const + { MOZ_ASSERT(state == Type2State::result); return *(T*)storage.addr(); } @@ -124,14 +125,16 @@ private: template template -struct MaybeOneOf::Type2State { +struct MaybeOneOf::Type2State +{ typedef MaybeOneOf Enclosing; static const typename Enclosing::State result = Enclosing::SomeT1; }; template template -struct MaybeOneOf::Type2State { +struct MaybeOneOf::Type2State +{ typedef MaybeOneOf Enclosing; static const typename Enclosing::State result = Enclosing::SomeT2; }; diff --git a/mfbt/MemoryChecking.h b/mfbt/MemoryChecking.h index ec290b37e8a..0642d758c06 100644 --- a/mfbt/MemoryChecking.h +++ b/mfbt/MemoryChecking.h @@ -63,9 +63,9 @@ void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t VALGRIND_MAKE_MEM_DEFINED((addr), (size)) #else -#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) -#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) +#define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while (0) +#define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while (0) #endif diff --git a/mfbt/Move.h b/mfbt/Move.h index 2a0f87c699f..08ae86fa57a 100644 --- a/mfbt/Move.h +++ b/mfbt/Move.h @@ -144,8 +144,8 @@ namespace mozilla { * - First, when a function template takes an argument that is an rvalue * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), * then when the argument is applied to an lvalue, the template argument - * resolves to 'T &'; and when it is applied to an rvalue, the template - * argument resolves to 'T &&'. Thus, in a call to C::C like: + * resolves to 'T&'; and when it is applied to an rvalue, the template + * argument resolves to 'T&&'. Thus, in a call to C::C like: * * X foo(int); * Y yy; diff --git a/mfbt/Pair.h b/mfbt/Pair.h index 0ee81290aa4..e9e8a769381 100644 --- a/mfbt/Pair.h +++ b/mfbt/Pair.h @@ -38,95 +38,99 @@ struct PairHelper; template struct PairHelper { - protected: - template - PairHelper(AArg&& a, BArg&& b) - : firstA(Forward(a)), - secondB(Forward(b)) - {} +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : mFirstA(Forward(aA)), + mSecondB(Forward(aB)) + {} - A& first() { return firstA; } - const A& first() const { return firstA; } - B& second() { return secondB; } - const B& second() const { return secondB; } + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } - void swap(PairHelper& other) { - Swap(firstA, other.firstA); - Swap(secondB, other.secondB); - } + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(mSecondB, aOther.mSecondB); + } - private: - A firstA; - B secondB; +private: + A mFirstA; + B mSecondB; }; template struct PairHelper : private B { - protected: - template - PairHelper(AArg&& a, BArg&& b) - : B(Forward(b)), - firstA(Forward(a)) - {} +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : B(Forward(aB)), + mFirstA(Forward(aA)) + {} - A& first() { return firstA; } - const A& first() const { return firstA; } - B& second() { return *this; } - const B& second() const { return *this; } + A& first() { return mFirstA; } + const A& first() const { return mFirstA; } + B& second() { return *this; } + const B& second() const { return *this; } - void swap(PairHelper& other) { - Swap(firstA, other.firstA); - Swap(static_cast(*this), static_cast(other)); - } + void swap(PairHelper& aOther) + { + Swap(mFirstA, aOther.mFirstA); + Swap(static_cast(*this), static_cast(aOther)); + } - private: - A firstA; +private: + A mFirstA; }; template struct PairHelper : private A { - protected: - template - PairHelper(AArg&& a, BArg&& b) - : A(Forward(a)), - secondB(Forward(b)) - {} +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + mSecondB(Forward(aB)) + {} - A& first() { return *this; } - const A& first() const { return *this; } - B& second() { return secondB; } - const B& second() const { return secondB; } + A& first() { return *this; } + const A& first() const { return *this; } + B& second() { return mSecondB; } + const B& second() const { return mSecondB; } - void swap(PairHelper& other) { - Swap(static_cast(*this), static_cast(other)); - Swap(secondB, other.secondB); - } + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(mSecondB, aOther.mSecondB); + } - private: - B secondB; +private: + B mSecondB; }; template struct PairHelper : private A, private B { - protected: - template - PairHelper(AArg&& a, BArg&& b) - : A(Forward(a)), - B(Forward(b)) - {} +protected: + template + PairHelper(AArg&& aA, BArg&& aB) + : A(Forward(aA)), + B(Forward(aB)) + {} - A& first() { return static_cast(*this); } - const A& first() const { return static_cast(*this); } - B& second() { return static_cast(*this); } - const B& second() const { return static_cast(*this); } + A& first() { return static_cast(*this); } + const A& first() const { return static_cast(*this); } + B& second() { return static_cast(*this); } + const B& second() const { return static_cast(*this); } - void swap(PairHelper& other) { - Swap(static_cast(*this), static_cast(other)); - Swap(static_cast(*this), static_cast(other)); - } + void swap(PairHelper& aOther) + { + Swap(static_cast(*this), static_cast(aOther)); + Swap(static_cast(*this), static_cast(aOther)); + } }; } // namespace detail @@ -148,33 +152,31 @@ template struct Pair : private detail::PairHelper { - typedef typename detail::PairHelper Base; + typedef typename detail::PairHelper Base; - public: - template - Pair(AArg&& a, BArg&& b) - : Base(Forward(a), Forward(b)) - {} +public: + template + Pair(AArg&& aA, BArg&& aB) + : Base(Forward(aA), Forward(aB)) + {} - /** The A instance. */ - using Base::first; - /** The B instance. */ - using Base::second; + /** The A instance. */ + using Base::first; + /** The B instance. */ + using Base::second; - /** Swap this pair with another pair. */ - void swap(Pair& other) { - Base::swap(other); - } + /** Swap this pair with another pair. */ + void swap(Pair& aOther) { Base::swap(aOther); } - private: - Pair(const Pair&) MOZ_DELETE; +private: + Pair(const Pair&) MOZ_DELETE; }; template void -Swap(Pair& x, Pair& y) +Swap(Pair& aX, Pair& aY) { - x.swap(y); + aX.swap(aY); } } // namespace mozilla diff --git a/mfbt/Poison.cpp b/mfbt/Poison.cpp index 02630273478..1e1c3f2d859 100644 --- a/mfbt/Poison.cpp +++ b/mfbt/Poison.cpp @@ -41,14 +41,14 @@ uintptr_t gMozillaPoisonSize; // file. #ifdef _WIN32 -static void * +static void* ReserveRegion(uintptr_t aRegion, uintptr_t aSize) { - return VirtualAlloc((void *)aRegion, aSize, MEM_RESERVE, PAGE_NOACCESS); + return VirtualAlloc((void*)aRegion, aSize, MEM_RESERVE, PAGE_NOACCESS); } static void -ReleaseRegion(void *aRegion, uintptr_t aSize) +ReleaseRegion(void* aRegion, uintptr_t aSize) { VirtualFree(aRegion, aSize, MEM_RELEASE); } @@ -77,7 +77,7 @@ GetDesiredRegionSize() #define RESERVE_FAILED 0 #elif defined(__OS2__) -static void * +static void* ReserveRegion(uintptr_t aRegion, uintptr_t aSize) { // OS/2 doesn't support allocation at an arbitrary address, @@ -86,7 +86,7 @@ ReserveRegion(uintptr_t aRegion, uintptr_t aSize) } static void -ReleaseRegion(void *aRegion, uintptr_t aSize) +ReleaseRegion(void* aRegion, uintptr_t aSize) { return; } @@ -112,7 +112,7 @@ GetDesiredRegionSize() #include "mozilla/TaggedAnonymousMemory.h" -static void * +static void* ReserveRegion(uintptr_t aRegion, uintptr_t aSize) { return MozTaggedAnonymousMmap(reinterpret_cast(aRegion), aSize, @@ -121,7 +121,7 @@ ReserveRegion(uintptr_t aRegion, uintptr_t aSize) } static void -ReleaseRegion(void *aRegion, uintptr_t aSize) +ReleaseRegion(void* aRegion, uintptr_t aSize) { munmap(aRegion, aSize); } @@ -147,7 +147,7 @@ GetDesiredRegionSize() #endif // system dependencies static_assert(sizeof(uintptr_t) == 4 || sizeof(uintptr_t) == 8, ""); -static_assert(sizeof(uintptr_t) == sizeof(void *), ""); +static_assert(sizeof(uintptr_t) == sizeof(void*), ""); static uintptr_t ReservePoisonArea(uintptr_t rgnsize) @@ -163,8 +163,8 @@ ReservePoisonArea(uintptr_t rgnsize) // First see if we can allocate the preferred poison address from the OS. uintptr_t candidate = (0xF0DEAFFF & ~(rgnsize-1)); - void *result = ReserveRegion(candidate, rgnsize); - if (result == (void *)candidate) { + void* result = ReserveRegion(candidate, rgnsize); + if (result == (void*)candidate) { // success - inaccessible page allocated return candidate; } diff --git a/mfbt/Range.h b/mfbt/Range.h index 1654cb39ea1..814a2821ad6 100644 --- a/mfbt/Range.h +++ b/mfbt/Range.h @@ -18,28 +18,26 @@ namespace mozilla { template class Range { - const RangedPtr mStart; - const RangedPtr mEnd; + const RangedPtr mStart; + const RangedPtr mEnd; - typedef void (Range::* ConvertibleToBool)(); - void nonNull() {} + typedef void (Range::* ConvertibleToBool)(); + void nonNull() {} - public: - Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} - Range(T* p, size_t len) - : mStart(p, p, p + len), - mEnd(p + len, p, p + len) - {} +public: + Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {} + Range(T* aPtr, size_t aLength) + : mStart(aPtr, aPtr, aPtr + aLength), + mEnd(aPtr + aLength, aPtr, aPtr + aLength) + {} - RangedPtr start() const { return mStart; } - RangedPtr end() const { return mEnd; } - size_t length() const { return mEnd - mStart; } + RangedPtr start() const { return mStart; } + RangedPtr end() const { return mEnd; } + size_t length() const { return mEnd - mStart; } - T& operator[](size_t offset) const { - return mStart[offset]; - } + T& operator[](size_t aOffset) const { return mStart[aOffset]; } - operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } + operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; } }; } // namespace mozilla diff --git a/mfbt/RangedPtr.h b/mfbt/RangedPtr.h index 4594fc5b79d..4d94035b904 100644 --- a/mfbt/RangedPtr.h +++ b/mfbt/RangedPtr.h @@ -43,216 +43,240 @@ namespace mozilla { template class RangedPtr { - T* ptr; + T* mPtr; #ifdef DEBUG - T* const rangeStart; - T* const rangeEnd; + T* const mRangeStart; + T* const mRangeEnd; #endif - typedef void (RangedPtr::* ConvertibleToBool)(); - void nonNull() {} + typedef void (RangedPtr::* ConvertibleToBool)(); + void nonNull() {} - void checkSanity() { - MOZ_ASSERT(rangeStart <= ptr); - MOZ_ASSERT(ptr <= rangeEnd); - } + void checkSanity() + { + MOZ_ASSERT(mRangeStart <= mPtr); + MOZ_ASSERT(mPtr <= mRangeEnd); + } - /* Creates a new pointer for |p|, restricted to this pointer's range. */ - RangedPtr create(T *p) const { + /* Creates a new pointer for |aPtr|, restricted to this pointer's range. */ + RangedPtr create(T* aPtr) const + { #ifdef DEBUG - return RangedPtr(p, rangeStart, rangeEnd); + return RangedPtr(aPtr, mRangeStart, mRangeEnd); #else - return RangedPtr(p, nullptr, size_t(0)); + return RangedPtr(aPtr, nullptr, size_t(0)); #endif - } + } - uintptr_t asUintptr() const { return uintptr_t(ptr); } + uintptr_t asUintptr() const { return reinterpret_cast(mPtr); } - public: - RangedPtr(T* p, T* start, T* end) - : ptr(p) +public: + RangedPtr(T* aPtr, T* aStart, T* aEnd) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(end) + , mRangeStart(aStart), mRangeEnd(aEnd) #endif - { - MOZ_ASSERT(rangeStart <= rangeEnd); - checkSanity(); - } - RangedPtr(T* p, T* start, size_t length) - : ptr(p) + { + MOZ_ASSERT(mRangeStart <= mRangeEnd); + checkSanity(); + } + RangedPtr(T* aPtr, T* aStart, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(start), rangeEnd(start + length) + , mRangeStart(aStart), mRangeEnd(aStart + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } - /* Equivalent to RangedPtr(p, p, length). */ - RangedPtr(T* p, size_t length) - : ptr(p) + /* Equivalent to RangedPtr(aPtr, aPtr, aLength). */ + RangedPtr(T* aPtr, size_t aLength) + : mPtr(aPtr) #ifdef DEBUG - , rangeStart(p), rangeEnd(p + length) + , mRangeStart(aPtr), mRangeEnd(aPtr + aLength) #endif - { - MOZ_ASSERT(length <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart)); - checkSanity(); - } + { + MOZ_ASSERT(aLength <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(reinterpret_cast(mRangeStart) + aLength * sizeof(T) >= + reinterpret_cast(mRangeStart)); + checkSanity(); + } - /* Equivalent to RangedPtr(arr, arr, N). */ - template - RangedPtr(T (&arr)[N]) - : ptr(arr) + /* Equivalent to RangedPtr(aArr, aArr, N). */ + template + RangedPtr(T (&aArr)[N]) + : mPtr(aArr) #ifdef DEBUG - , rangeStart(arr), rangeEnd(arr + N) + , mRangeStart(aArr), mRangeEnd(aArr + N) #endif - { - checkSanity(); - } + { + checkSanity(); + } - T* get() const { - return ptr; - } + T* get() const { return mPtr; } - operator ConvertibleToBool() const { return ptr ? &RangedPtr::nonNull : 0; } + operator ConvertibleToBool() const { return mPtr ? &RangedPtr::nonNull : 0; } - /* - * You can only assign one RangedPtr into another if the two pointers have - * the same valid range: - * - * char arr1[] = "hi"; - * char arr2[] = "bye"; - * RangedPtr p1(arr1, 2); - * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works - * p1 = RangedPtr(arr2, 3); // asserts - */ - RangedPtr& operator=(const RangedPtr& other) { - MOZ_ASSERT(rangeStart == other.rangeStart); - MOZ_ASSERT(rangeEnd == other.rangeEnd); - ptr = other.ptr; - checkSanity(); - return *this; - } + /* + * You can only assign one RangedPtr into another if the two pointers have + * the same valid range: + * + * char arr1[] = "hi"; + * char arr2[] = "bye"; + * RangedPtr p1(arr1, 2); + * p1 = RangedPtr(arr1 + 1, arr1, arr1 + 2); // works + * p1 = RangedPtr(arr2, 3); // asserts + */ + RangedPtr& operator=(const RangedPtr& aOther) + { + MOZ_ASSERT(mRangeStart == aOther.mRangeStart); + MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd); + mPtr = aOther.mPtr; + checkSanity(); + return *this; + } - RangedPtr operator+(size_t inc) { - MOZ_ASSERT(inc <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() + inc * sizeof(T) >= asUintptr()); - return create(ptr + inc); - } + RangedPtr operator+(size_t aInc) + { + MOZ_ASSERT(aInc <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() + aInc * sizeof(T) >= asUintptr()); + return create(mPtr + aInc); + } - RangedPtr operator-(size_t dec) { - MOZ_ASSERT(dec <= size_t(-1) / sizeof(T)); - MOZ_ASSERT(asUintptr() - dec * sizeof(T) <= asUintptr()); - return create(ptr - dec); - } + RangedPtr operator-(size_t aDec) + { + MOZ_ASSERT(aDec <= size_t(-1) / sizeof(T)); + MOZ_ASSERT(asUintptr() - aDec * sizeof(T) <= asUintptr()); + return create(mPtr - aDec); + } - /* - * You can assign a raw pointer into a RangedPtr if the raw pointer is - * within the range specified at creation. - */ - template - RangedPtr& operator=(U* p) { - *this = create(p); - return *this; - } + /* + * You can assign a raw pointer into a RangedPtr if the raw pointer is + * within the range specified at creation. + */ + template + RangedPtr& operator=(U* aPtr) + { + *this = create(aPtr); + return *this; + } - template - RangedPtr& operator=(const RangedPtr& p) { - MOZ_ASSERT(rangeStart <= p.ptr); - MOZ_ASSERT(p.ptr <= rangeEnd); - ptr = p.ptr; - checkSanity(); - return *this; - } + template + RangedPtr& operator=(const RangedPtr& aPtr) + { + MOZ_ASSERT(mRangeStart <= aPtr.mPtr); + MOZ_ASSERT(aPtr.mPtr <= mRangeEnd); + mPtr = aPtr.mPtr; + checkSanity(); + return *this; + } - RangedPtr& operator++() { - return (*this += 1); - } + RangedPtr& operator++() + { + return (*this += 1); + } - RangedPtr operator++(int) { - RangedPtr rcp = *this; - ++*this; - return rcp; - } + RangedPtr operator++(int) + { + RangedPtr rcp = *this; + ++*this; + return rcp; + } - RangedPtr& operator--() { - return (*this -= 1); - } + RangedPtr& operator--() + { + return (*this -= 1); + } - RangedPtr operator--(int) { - RangedPtr rcp = *this; - --*this; - return rcp; - } + RangedPtr operator--(int) + { + RangedPtr rcp = *this; + --*this; + return rcp; + } - RangedPtr& operator+=(size_t inc) { - *this = *this + inc; - return *this; - } + RangedPtr& operator+=(size_t aInc) + { + *this = *this + aInc; + return *this; + } - RangedPtr& operator-=(size_t dec) { - *this = *this - dec; - return *this; - } + RangedPtr& operator-=(size_t aDec) + { + *this = *this - aDec; + return *this; + } - T& operator[](int index) const { - MOZ_ASSERT(size_t(index > 0 ? index : -index) <= size_t(-1) / sizeof(T)); - return *create(ptr + index); - } + T& operator[](int aIndex) const + { + MOZ_ASSERT(size_t(aIndex > 0 ? aIndex : -aIndex) <= size_t(-1) / sizeof(T)); + return *create(mPtr + aIndex); + } - T& operator*() const { - MOZ_ASSERT(ptr >= rangeStart); - MOZ_ASSERT(ptr < rangeEnd); - return *ptr; - } + T& operator*() const + { + MOZ_ASSERT(mPtr >= mRangeStart); + MOZ_ASSERT(mPtr < mRangeEnd); + return *mPtr; + } - template - bool operator==(const RangedPtr& other) const { - return ptr == other.ptr; - } - template - bool operator!=(const RangedPtr& other) const { - return !(*this == other); - } + template + bool operator==(const RangedPtr& aOther) const + { + return mPtr == aOther.mPtr; + } + template + bool operator!=(const RangedPtr& aOther) const + { + return !(*this == aOther); + } - template - bool operator==(const U* u) const { - return ptr == u; - } - template - bool operator!=(const U* u) const { - return !(*this == u); - } + template + bool operator==(const U* u) const + { + return mPtr == u; + } + template + bool operator!=(const U* u) const + { + return !(*this == u); + } - template - bool operator<(const RangedPtr& other) const { - return ptr < other.ptr; - } - template - bool operator<=(const RangedPtr& other) const { - return ptr <= other.ptr; - } + template + bool operator<(const RangedPtr& aOther) const + { + return mPtr < aOther.mPtr; + } + template + bool operator<=(const RangedPtr& aOther) const + { + return mPtr <= aOther.mPtr; + } - template - bool operator>(const RangedPtr& other) const { - return ptr > other.ptr; - } - template - bool operator>=(const RangedPtr& other) const { - return ptr >= other.ptr; - } + template + bool operator>(const RangedPtr& aOther) const + { + return mPtr > aOther.mPtr; + } + template + bool operator>=(const RangedPtr& aOther) const + { + return mPtr >= aOther.mPtr; + } - size_t operator-(const RangedPtr& other) const { - MOZ_ASSERT(ptr >= other.ptr); - return PointerRangeSize(other.ptr, ptr); - } + size_t operator-(const RangedPtr& aOther) const + { + MOZ_ASSERT(mPtr >= aOther.mPtr); + return PointerRangeSize(aOther.mPtr, mPtr); + } - private: - RangedPtr() MOZ_DELETE; - T* operator&() MOZ_DELETE; +private: + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/mfbt/ReentrancyGuard.h b/mfbt/ReentrancyGuard.h index d589f368a25..557c61015eb 100644 --- a/mfbt/ReentrancyGuard.h +++ b/mfbt/ReentrancyGuard.h @@ -18,38 +18,38 @@ namespace mozilla { /* Useful for implementing containers that assert non-reentrancy */ class ReentrancyGuard { - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER #ifdef DEBUG - bool& entered; + bool& mEntered; #endif - public: - template +public: + template #ifdef DEBUG - ReentrancyGuard(T& obj - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : entered(obj.entered) + ReentrancyGuard(T& aObj + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mEntered(aObj.mEntered) #else - ReentrancyGuard(T& - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + ReentrancyGuard(T& + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) #endif - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; #ifdef DEBUG - MOZ_ASSERT(!entered); - entered = true; + MOZ_ASSERT(!mEntered); + mEntered = true; #endif - } - ~ReentrancyGuard() - { + } + ~ReentrancyGuard() + { #ifdef DEBUG - entered = false; + mEntered = false; #endif - } + } - private: - ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; - void operator=(const ReentrancyGuard&) MOZ_DELETE; +private: + ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; + void operator=(const ReentrancyGuard&) MOZ_DELETE; }; } // namespace mozilla diff --git a/mfbt/RefPtr.h b/mfbt/RefPtr.h index aef736d4a27..4901067b4c9 100644 --- a/mfbt/RefPtr.h +++ b/mfbt/RefPtr.h @@ -12,13 +12,15 @@ #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" +#include "mozilla/NullPtr.h" #include "mozilla/RefCountType.h" #include "mozilla/TypeTraits.h" #if defined(MOZILLA_INTERNAL_API) #include "nsXPCOM.h" #endif -#if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) +#if defined(MOZILLA_INTERNAL_API) && \ + (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) #define MOZ_REFCOUNTED_LEAK_CHECKING #endif @@ -65,20 +67,21 @@ const MozRefCountType DEAD = 0xffffdead; #ifdef MOZ_REFCOUNTED_LEAK_CHECKING class RefCountLogger { - public: - static void logAddRef(const void* aPointer, MozRefCountType aRefCount, - const char* aTypeName, uint32_t aInstanceSize) - { - MOZ_ASSERT(aRefCount != DEAD); - NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, aInstanceSize); - } +public: + static void logAddRef(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName, uint32_t aInstanceSize) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogAddRef(const_cast(aPointer), aRefCount, aTypeName, + aInstanceSize); + } - static void logRelease(const void* aPointer, MozRefCountType aRefCount, - const char* aTypeName) - { - MOZ_ASSERT(aRefCount != DEAD); - NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); - } + static void logRelease(const void* aPointer, MozRefCountType aRefCount, + const char* aTypeName) + { + MOZ_ASSERT(aRefCount != DEAD); + NS_LogRelease(const_cast(aPointer), aRefCount, aTypeName); + } }; #endif @@ -92,66 +95,69 @@ enum RefCountAtomicity template class RefCounted { - friend class RefPtr; + friend class RefPtr; - protected: - RefCounted() : refCnt(0) { } - ~RefCounted() { - MOZ_ASSERT(refCnt == detail::DEAD); - } +protected: + RefCounted() : mRefCnt(0) {} + ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); } - public: - // Compatibility with nsRefPtr. - void AddRef() const { - // Note: this method must be thread safe for AtomicRefCounted. - MOZ_ASSERT(int32_t(refCnt) >= 0); +public: + // Compatibility with nsRefPtr. + void AddRef() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) >= 0); #ifndef MOZ_REFCOUNTED_LEAK_CHECKING - ++refCnt; + ++mRefCnt; #else - const char* type = static_cast(this)->typeName(); - uint32_t size = static_cast(this)->typeSize(); - const void* ptr = static_cast(this); - MozRefCountType cnt = ++refCnt; - detail::RefCountLogger::logAddRef(ptr, cnt, type, size); + const char* type = static_cast(this)->typeName(); + uint32_t size = static_cast(this)->typeSize(); + const void* ptr = static_cast(this); + MozRefCountType cnt = ++mRefCnt; + detail::RefCountLogger::logAddRef(ptr, cnt, type, size); #endif - } + } - void Release() const { - // Note: this method must be thread safe for AtomicRefCounted. - MOZ_ASSERT(int32_t(refCnt) > 0); + void Release() const + { + // Note: this method must be thread safe for AtomicRefCounted. + MOZ_ASSERT(int32_t(mRefCnt) > 0); #ifndef MOZ_REFCOUNTED_LEAK_CHECKING - MozRefCountType cnt = --refCnt; + MozRefCountType cnt = --mRefCnt; #else - const char* type = static_cast(this)->typeName(); - const void* ptr = static_cast(this); - MozRefCountType cnt = --refCnt; - // Note: it's not safe to touch |this| after decrementing the refcount, - // except for below. - detail::RefCountLogger::logRelease(ptr, cnt, type); + const char* type = static_cast(this)->typeName(); + const void* ptr = static_cast(this); + MozRefCountType cnt = --mRefCnt; + // Note: it's not safe to touch |this| after decrementing the refcount, + // except for below. + detail::RefCountLogger::logRelease(ptr, cnt, type); #endif - if (0 == cnt) { - // Because we have atomically decremented the refcount above, only - // one thread can get a 0 count here, so as long as we can assume that - // everything else in the system is accessing this object through - // RefPtrs, it's safe to access |this| here. + if (0 == cnt) { + // Because we have atomically decremented the refcount above, only + // one thread can get a 0 count here, so as long as we can assume that + // everything else in the system is accessing this object through + // RefPtrs, it's safe to access |this| here. #ifdef DEBUG - refCnt = detail::DEAD; + mRefCnt = detail::DEAD; #endif - delete static_cast(this); - } + delete static_cast(this); } + } - // Compatibility with wtf::RefPtr. - void ref() { AddRef(); } - void deref() { Release(); } - MozRefCountType refCount() const { return refCnt; } - bool hasOneRef() const { - MOZ_ASSERT(refCnt > 0); - return refCnt == 1; - } + // Compatibility with wtf::RefPtr. + void ref() { AddRef(); } + void deref() { Release(); } + MozRefCountType refCount() const { return mRefCnt; } + bool hasOneRef() const + { + MOZ_ASSERT(mRefCnt > 0); + return mRefCnt == 1; + } - private: - mutable typename Conditional, MozRefCountType>::Type refCnt; +private: + mutable typename Conditional, + MozRefCountType>::Type mRefCnt; }; #ifdef MOZ_REFCOUNTED_LEAK_CHECKING @@ -169,16 +175,17 @@ class RefCounted const char* typeName() const { return #T; } \ size_t typeSize() const { return sizeof(*this); } -} +} // namespace detail template class RefCounted : public detail::RefCounted { - public: - ~RefCounted() { - static_assert(IsBaseOf::value, - "T must derive from RefCounted"); - } +public: + ~RefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from RefCounted"); + } }; namespace external { @@ -191,16 +198,18 @@ namespace external { * instead. */ template -class AtomicRefCounted : public mozilla::detail::RefCounted +class AtomicRefCounted : + public mozilla::detail::RefCounted { - public: - ~AtomicRefCounted() { - static_assert(IsBaseOf::value, - "T must derive from AtomicRefCounted"); - } +public: + ~AtomicRefCounted() + { + static_assert(IsBaseOf::value, + "T must derive from AtomicRefCounted"); + } }; -} +} // namespace external /** * RefPtr points to a refcounted thing that has AddRef and Release @@ -215,73 +224,83 @@ class AtomicRefCounted : public mozilla::detail::RefCounted class RefPtr { - // To allow them to use unref() - friend class TemporaryRef; - friend class OutParamRef; + // To allow them to use unref() + friend class TemporaryRef; + friend class OutParamRef; - struct DontRef {}; + struct DontRef {}; - public: - RefPtr() : ptr(0) { } - RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {} - MOZ_IMPLICIT RefPtr(const TemporaryRef& o) : ptr(o.drop()) {} - MOZ_IMPLICIT RefPtr(T* t) : ptr(ref(t)) {} +public: + RefPtr() : mPtr(0) {} + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {} + MOZ_IMPLICIT RefPtr(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} + MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {} - template - RefPtr(const RefPtr& o) : ptr(ref(o.get())) {} + template + RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.get())) {} - ~RefPtr() { unref(ptr); } + ~RefPtr() { unref(mPtr); } - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.ptr)); - return *this; - } - RefPtr& operator=(const TemporaryRef& o) { - assign(o.drop()); - return *this; - } - RefPtr& operator=(T* t) { - assign(ref(t)); - return *this; + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.mPtr)); + return *this; + } + RefPtr& operator=(const TemporaryRef& aOther) + { + assign(aOther.drop()); + return *this; + } + RefPtr& operator=(T* aVal) + { + assign(ref(aVal)); + return *this; + } + + template + RefPtr& operator=(const RefPtr& aOther) + { + assign(ref(aOther.get())); + return *this; + } + + TemporaryRef forget() + { + T* tmp = mPtr; + mPtr = nullptr; + return TemporaryRef(tmp, DontRef()); + } + + T* get() const { return mPtr; } + operator T*() const { return mPtr; } + T* operator->() const { return mPtr; } + T& operator*() const { return *mPtr; } + template + operator TemporaryRef() { return TemporaryRef(mPtr); } + +private: + void assign(T* aVal) + { + unref(mPtr); + mPtr = aVal; + } + + T* mPtr; + + static MOZ_ALWAYS_INLINE T* ref(T* aVal) + { + if (aVal) { + aVal->AddRef(); } + return aVal; + } - template - RefPtr& operator=(const RefPtr& o) { - assign(ref(o.get())); - return *this; - } - - TemporaryRef forget() { - T* tmp = ptr; - ptr = 0; - return TemporaryRef(tmp, DontRef()); - } - - T* get() const { return ptr; } - operator T*() const { return ptr; } - T* operator->() const { return ptr; } - T& operator*() const { return *ptr; } - template - operator TemporaryRef() { return TemporaryRef(ptr); } - - private: - void assign(T* t) { - unref(ptr); - ptr = t; - } - - T* ptr; - - static MOZ_ALWAYS_INLINE T* ref(T* t) { - if (t) - t->AddRef(); - return t; - } - - static MOZ_ALWAYS_INLINE void unref(T* t) { - if (t) - t->Release(); + static MOZ_ALWAYS_INLINE void unref(T* aVal) + { + if (aVal) { + aVal->Release(); } + } }; /** @@ -293,33 +312,34 @@ class RefPtr template class TemporaryRef { - // To allow it to construct TemporaryRef from a bare T* - friend class RefPtr; + // To allow it to construct TemporaryRef from a bare T* + friend class RefPtr; - typedef typename RefPtr::DontRef DontRef; + typedef typename RefPtr::DontRef DontRef; - public: - MOZ_IMPLICIT TemporaryRef(T* t) : ptr(RefPtr::ref(t)) {} - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} +public: + MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr::ref(aVal)) {} + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - template - TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {} + template + TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {} - ~TemporaryRef() { RefPtr::unref(ptr); } + ~TemporaryRef() { RefPtr::unref(mPtr); } - T* drop() const { - T* tmp = ptr; - ptr = 0; - return tmp; - } + T* drop() const + { + T* tmp = mPtr; + mPtr = nullptr; + return tmp; + } - private: - TemporaryRef(T* t, const DontRef&) : ptr(t) {} +private: + TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {} - mutable T* ptr; + mutable T* mPtr; - TemporaryRef() MOZ_DELETE; - void operator=(const TemporaryRef&) MOZ_DELETE; + TemporaryRef() MOZ_DELETE; + void operator=(const TemporaryRef&) MOZ_DELETE; }; /** @@ -339,24 +359,25 @@ class TemporaryRef template class OutParamRef { - friend OutParamRef byRef(RefPtr&); + friend OutParamRef byRef(RefPtr&); - public: - ~OutParamRef() { - RefPtr::unref(refPtr.ptr); - refPtr.ptr = tmp; - } +public: + ~OutParamRef() + { + RefPtr::unref(mRefPtr.mPtr); + mRefPtr.mPtr = mTmp; + } - operator T**() { return &tmp; } + operator T**() { return &mTmp; } - private: - explicit OutParamRef(RefPtr& p) : refPtr(p), tmp(p.get()) {} +private: + explicit OutParamRef(RefPtr& p) : mRefPtr(p), mTmp(p.get()) {} - RefPtr& refPtr; - T* tmp; + RefPtr& mRefPtr; + T* mTmp; - OutParamRef() MOZ_DELETE; - OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** @@ -364,9 +385,9 @@ class OutParamRef */ template OutParamRef -byRef(RefPtr& ptr) +byRef(RefPtr& aPtr) { - return OutParamRef(ptr); + return OutParamRef(aPtr); } } // namespace mozilla @@ -382,19 +403,20 @@ using namespace mozilla; struct Foo : public RefCounted { MOZ_DECLARE_REFCOUNTED_TYPENAME(Foo) - Foo() : dead(false) { } - ~Foo() { - MOZ_ASSERT(!dead); - dead = true; - numDestroyed++; + Foo() : mDead(false) {} + ~Foo() + { + MOZ_ASSERT(!mDead); + mDead = true; + sNumDestroyed++; } - bool dead; - static int numDestroyed; + bool mDead; + static int sNumDestroyed; }; -int Foo::numDestroyed; +int Foo::sNumDestroyed; -struct Bar : public Foo { }; +struct Bar : public Foo {}; TemporaryRef NewFoo() @@ -445,25 +467,25 @@ main(int argc, char** argv) // This should blow up // Foo* f = new Foo(); delete f; - MOZ_ASSERT(0 == Foo::numDestroyed); + MOZ_ASSERT(0 == Foo::sNumDestroyed); { RefPtr f = new Foo(); MOZ_ASSERT(f->refCount() == 1); } - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); { RefPtr f1 = NewFoo(); RefPtr f2(NewFoo()); - MOZ_ASSERT(1 == Foo::numDestroyed); + MOZ_ASSERT(1 == Foo::sNumDestroyed); } - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); { RefPtr b = NewBar(); - MOZ_ASSERT(3 == Foo::numDestroyed); + MOZ_ASSERT(3 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); { RefPtr f1; @@ -471,56 +493,56 @@ main(int argc, char** argv) f1 = new Foo(); RefPtr f2(f1); RefPtr f3 = f2; - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(4 == Foo::numDestroyed); + MOZ_ASSERT(4 == Foo::sNumDestroyed); } - MOZ_ASSERT(5 == Foo::numDestroyed); + MOZ_ASSERT(5 == Foo::sNumDestroyed); { RefPtr f = new Foo(); f.forget(); - MOZ_ASSERT(6 == Foo::numDestroyed); + MOZ_ASSERT(6 == Foo::sNumDestroyed); } { RefPtr f = new Foo(); GetNewFoo(byRef(f)); - MOZ_ASSERT(7 == Foo::numDestroyed); + MOZ_ASSERT(7 == Foo::sNumDestroyed); } - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(byRef(f)); - MOZ_ASSERT(8 == Foo::numDestroyed); + MOZ_ASSERT(8 == Foo::sNumDestroyed); } - MOZ_ASSERT(9 == Foo::numDestroyed); + MOZ_ASSERT(9 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetNewFoo(&f); - MOZ_ASSERT(10 == Foo::numDestroyed); + MOZ_ASSERT(10 == Foo::sNumDestroyed); } - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); { RefPtr f = new Foo(); GetPassedFoo(&f); - MOZ_ASSERT(11 == Foo::numDestroyed); + MOZ_ASSERT(11 == Foo::sNumDestroyed); } - MOZ_ASSERT(12 == Foo::numDestroyed); + MOZ_ASSERT(12 == Foo::sNumDestroyed); { RefPtr f1 = new Bar(); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); { RefPtr f = GetNullFoo(); - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); } - MOZ_ASSERT(13 == Foo::numDestroyed); + MOZ_ASSERT(13 == Foo::sNumDestroyed); return 0; } diff --git a/mfbt/RollingMean.h b/mfbt/RollingMean.h index 5328081ab16..5add14c879f 100644 --- a/mfbt/RollingMean.h +++ b/mfbt/RollingMean.h @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-w idth: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -28,78 +29,85 @@ namespace mozilla { template class RollingMean { - private: - size_t mInsertIndex; - size_t mMaxValues; - Vector mValues; - S mTotal; +private: + size_t mInsertIndex; + size_t mMaxValues; + Vector mValues; + S mTotal; - public: - static_assert(!IsFloatingPoint::value, - "floating-point types are unsupported due to rounding " - "errors"); +public: + static_assert(!IsFloatingPoint::value, + "floating-point types are unsupported due to rounding " + "errors"); - explicit RollingMean(size_t aMaxValues) - : mInsertIndex(0), - mMaxValues(aMaxValues), - mTotal(0) - { - MOZ_ASSERT(aMaxValues > 0); - } + explicit RollingMean(size_t aMaxValues) + : mInsertIndex(0), + mMaxValues(aMaxValues), + mTotal(0) + { + MOZ_ASSERT(aMaxValues > 0); + } - RollingMean& operator=(RollingMean&& aOther) { - MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); - this->~RollingMean(); - new(this) RollingMean(aOther.mMaxValues); - mInsertIndex = aOther.mInsertIndex; - mTotal = aOther.mTotal; - mValues.swap(aOther.mValues); - return *this; - } + RollingMean& operator=(RollingMean&& aOther) + { + MOZ_ASSERT(this != &aOther, "self-assignment is forbidden"); + this->~RollingMean(); + new(this) RollingMean(aOther.mMaxValues); + mInsertIndex = aOther.mInsertIndex; + mTotal = aOther.mTotal; + mValues.swap(aOther.mValues); + return *this; + } - /** - * Insert a value into the rolling mean. - */ - bool insert(T aValue) { - MOZ_ASSERT(mValues.length() <= mMaxValues); + /** + * Insert a value into the rolling mean. + */ + bool insert(T aValue) + { + MOZ_ASSERT(mValues.length() <= mMaxValues); - if (mValues.length() == mMaxValues) { - mTotal = mTotal - mValues[mInsertIndex] + aValue; - mValues[mInsertIndex] = aValue; - } else { - if (!mValues.append(aValue)) - return false; - mTotal = mTotal + aValue; + if (mValues.length() == mMaxValues) { + mTotal = mTotal - mValues[mInsertIndex] + aValue; + mValues[mInsertIndex] = aValue; + } else { + if (!mValues.append(aValue)) { + return false; } - - mInsertIndex = (mInsertIndex + 1) % mMaxValues; - return true; + mTotal = mTotal + aValue; } - /** - * Calculate the rolling mean. - */ - T mean() { - MOZ_ASSERT(!empty()); - return T(mTotal / mValues.length()); - } + mInsertIndex = (mInsertIndex + 1) % mMaxValues; + return true; + } - bool empty() { - return mValues.empty(); - } + /** + * Calculate the rolling mean. + */ + T mean() + { + MOZ_ASSERT(!empty()); + return T(mTotal / mValues.length()); + } - /** - * Remove all values from the rolling mean. - */ - void clear() { - mValues.clear(); - mInsertIndex = 0; - mTotal = T(0); - } + bool empty() + { + return mValues.empty(); + } - size_t maxValues() { - return mMaxValues; - } + /** + * Remove all values from the rolling mean. + */ + void clear() + { + mValues.clear(); + mInsertIndex = 0; + mTotal = T(0); + } + + size_t maxValues() + { + return mMaxValues; + } }; } // namespace mozilla diff --git a/mfbt/SHA1.cpp b/mfbt/SHA1.cpp index f11b064ec7c..da4cb16a19d 100644 --- a/mfbt/SHA1.cpp +++ b/mfbt/SHA1.cpp @@ -1,3 +1,5 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -12,14 +14,14 @@ using mozilla::NativeEndian; using mozilla::SHA1Sum; static inline uint32_t -SHA_ROTL(uint32_t t, uint32_t n) +SHA_ROTL(uint32_t aT, uint32_t aN) { - MOZ_ASSERT(n < 32); - return (t << n) | (t >> (32 - n)); + MOZ_ASSERT(aN < 32); + return (aT << aN) | (aT >> (32 - aN)); } static void -shaCompress(volatile unsigned* X, const uint32_t* datain); +shaCompress(volatile unsigned* aX, const uint32_t* aBuf); #define SHA_F1(X, Y, Z) ((((Y) ^ (Z)) & (X)) ^ (Z)) #define SHA_F2(X, Y, Z) ((X) ^ (Y) ^ (Z)) @@ -29,14 +31,14 @@ shaCompress(volatile unsigned* X, const uint32_t* datain); #define SHA_MIX(n, a, b, c) XW(n) = SHA_ROTL(XW(a) ^ XW(b) ^ XW(c) ^XW(n), 1) SHA1Sum::SHA1Sum() - : size(0), mDone(false) + : mSize(0), mDone(false) { // Initialize H with constants from FIPS180-1. - H[0] = 0x67452301L; - H[1] = 0xefcdab89L; - H[2] = 0x98badcfeL; - H[3] = 0x10325476L; - H[4] = 0xc3d2e1f0L; + mH[0] = 0x67452301L; + mH[1] = 0xefcdab89L; + mH[2] = 0x98badcfeL; + mH[3] = 0x10325476L; + mH[4] = 0xc3d2e1f0L; } /* @@ -79,42 +81,46 @@ SHA1Sum::SHA1Sum() * SHA: Add data to context. */ void -SHA1Sum::update(const void* dataIn, uint32_t len) +SHA1Sum::update(const void* aData, uint32_t aLen) { MOZ_ASSERT(!mDone, "SHA1Sum can only be used to compute a single hash."); - const uint8_t* data = static_cast(dataIn); + const uint8_t* data = static_cast(aData); - if (len == 0) + if (aLen == 0) { return; + } /* Accumulate the byte count. */ - unsigned int lenB = static_cast(size) & 63U; + unsigned int lenB = static_cast(mSize) & 63U; - size += len; + mSize += aLen; /* Read the data into W and process blocks as they get full. */ unsigned int togo; if (lenB > 0) { togo = 64U - lenB; - if (len < togo) - togo = len; - memcpy(u.b + lenB, data, togo); - len -= togo; + if (aLen < togo) { + togo = aLen; + } + memcpy(mU.mB + lenB, data, togo); + aLen -= togo; data += togo; lenB = (lenB + togo) & 63U; - if (!lenB) - shaCompress(&H[H2X], u.w); + if (!lenB) { + shaCompress(&mH[H2X], mU.mW); + } } - while (len >= 64U) { - len -= 64U; - shaCompress(&H[H2X], reinterpret_cast(data)); + while (aLen >= 64U) { + aLen -= 64U; + shaCompress(&mH[H2X], reinterpret_cast(data)); data += 64U; } - if (len > 0) - memcpy(u.b, data, len); + if (aLen > 0) { + memcpy(mU.mB, data, aLen); + } } @@ -122,12 +128,12 @@ SHA1Sum::update(const void* dataIn, uint32_t len) * SHA: Generate hash value */ void -SHA1Sum::finish(SHA1Sum::Hash& hashOut) +SHA1Sum::finish(SHA1Sum::Hash& aHashOut) { MOZ_ASSERT(!mDone, "SHA1Sum can only be used to compute a single hash."); - uint64_t size2 = size; - uint32_t lenB = uint32_t(size2) & 63; + uint64_t size = mSize; + uint32_t lenB = uint32_t(size) & 63; static const uint8_t bulk_pad[64] = { 0x80,0,0,0,0,0,0,0,0,0, @@ -136,21 +142,21 @@ SHA1Sum::finish(SHA1Sum::Hash& hashOut) /* Pad with a binary 1 (e.g. 0x80), then zeroes, then length in bits. */ update(bulk_pad, (((55 + 64) - lenB) & 63) + 1); - MOZ_ASSERT((uint32_t(size) & 63) == 56); + MOZ_ASSERT((uint32_t(mSize) & 63) == 56); /* Convert size from bytes to bits. */ - size2 <<= 3; - u.w[14] = NativeEndian::swapToBigEndian(uint32_t(size2 >> 32)); - u.w[15] = NativeEndian::swapToBigEndian(uint32_t(size2)); - shaCompress(&H[H2X], u.w); + size <<= 3; + mU.mW[14] = NativeEndian::swapToBigEndian(uint32_t(size >> 32)); + mU.mW[15] = NativeEndian::swapToBigEndian(uint32_t(size)); + shaCompress(&mH[H2X], mU.mW); /* Output hash. */ - u.w[0] = NativeEndian::swapToBigEndian(H[0]); - u.w[1] = NativeEndian::swapToBigEndian(H[1]); - u.w[2] = NativeEndian::swapToBigEndian(H[2]); - u.w[3] = NativeEndian::swapToBigEndian(H[3]); - u.w[4] = NativeEndian::swapToBigEndian(H[4]); - memcpy(hashOut, u.w, 20); + mU.mW[0] = NativeEndian::swapToBigEndian(mH[0]); + mU.mW[1] = NativeEndian::swapToBigEndian(mH[1]); + mU.mW[2] = NativeEndian::swapToBigEndian(mH[2]); + mU.mW[3] = NativeEndian::swapToBigEndian(mH[3]); + mU.mW[4] = NativeEndian::swapToBigEndian(mH[4]); + memcpy(aHashOut, mU.mW, 20); mDone = true; } @@ -185,7 +191,7 @@ SHA1Sum::finish(SHA1Sum::Hash& hashOut) * W array in the stack by creating a W array of 80 members, each of * whose elements is assigned only once. It also separated the computations * of the W array values and the computations of the values for the 5 - * state variables into two separate passes, W's, then A-E's so that the + * state variables into two separate passes, W's, then A-E's so that the * second pass could be done all in registers (except for accessing the W * array) on machines with fewer registers. The method is suboptimal * for machines with enough registers to do it all in one pass, and it @@ -202,12 +208,12 @@ SHA1Sum::finish(SHA1Sum::Hash& hashOut) * code on AMD64. */ static void -shaCompress(volatile unsigned *X, const uint32_t *inbuf) +shaCompress(volatile unsigned* aX, const uint32_t* aBuf) { unsigned A, B, C, D, E; -#define XH(n) X[n - H2X] -#define XW(n) X[n - W2X] +#define XH(n) aX[n - H2X] +#define XW(n) aX[n - W2X] #define K0 0x5a827999L #define K1 0x6ed9eba1L @@ -223,7 +229,7 @@ shaCompress(volatile unsigned *X, const uint32_t *inbuf) #define SHA_RND4(a, b, c, d, e, n) \ a = SHA_ROTL(b ,5) + SHA_F4(c, d, e) + a + XW(n) + K3; c = SHA_ROTL(c, 30) -#define LOAD(n) XW(n) = NativeEndian::swapToBigEndian(inbuf[n]) +#define LOAD(n) XW(n) = NativeEndian::swapToBigEndian(aBuf[n]) A = XH(0); B = XH(1); diff --git a/mfbt/SHA1.h b/mfbt/SHA1.h index b167648540b..ddccaa67e70 100644 --- a/mfbt/SHA1.h +++ b/mfbt/SHA1.h @@ -36,25 +36,26 @@ namespace mozilla { */ class SHA1Sum { - union { - uint32_t w[16]; /* input buffer */ - uint8_t b[64]; - } u; - uint64_t size; /* count of hashed bytes. */ - unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ - bool mDone; + union + { + uint32_t mW[16]; /* input buffer */ + uint8_t mB[64]; + } mU; + uint64_t mSize; /* count of hashed bytes. */ + unsigned mH[22]; /* 5 state variables, 16 tmp values, 1 extra */ + bool mDone; - public: - MFBT_API SHA1Sum(); +public: + MFBT_API SHA1Sum(); - static const size_t HashSize = 20; - typedef uint8_t Hash[HashSize]; + static const size_t kHashSize = 20; + typedef uint8_t Hash[kHashSize]; - /* Add len bytes of dataIn to the data sequence being hashed. */ - MFBT_API void update(const void* dataIn, uint32_t len); + /* Add len bytes of dataIn to the data sequence being hashed. */ + MFBT_API void update(const void* aData, uint32_t aLength); - /* Compute the final hash of all data into hashOut. */ - MFBT_API void finish(SHA1Sum::Hash& hashOut); + /* Compute the final hash of all data into hashOut. */ + MFBT_API void finish(SHA1Sum::Hash& aHashOut); }; } /* namespace mozilla */ diff --git a/mfbt/Scoped.h b/mfbt/Scoped.h index 11fead1c1f5..3f854d63758 100644 --- a/mfbt/Scoped.h +++ b/mfbt/Scoped.h @@ -64,7 +64,8 @@ namespace mozilla { * Scoped is a helper to create RAII wrappers * Type argument |Traits| is expected to have the following structure: * - * struct Traits { + * struct Traits + * { * // Define the type of the value stored in the wrapper * typedef value_type type; * // Returns the value corresponding to the uninitialized or freed state @@ -77,103 +78,102 @@ namespace mozilla { template class Scoped { - public: - typedef typename Traits::type Resource; +public: + typedef typename Traits::type Resource; - explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) - : value(Traits::empty()) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } + explicit Scoped(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) + : mValue(Traits::empty()) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - explicit Scoped(const Resource& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(v) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } + explicit Scoped(const Resource& aValue + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(aValue) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } - /* Move constructor. */ - explicit Scoped(Scoped&& v - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : value(Move(v.value)) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - v.value = Traits::empty(); - } + /* Move constructor. */ + explicit Scoped(Scoped&& aOther + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mValue(Move(aOther.mValue)) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + aOther.mValue = Traits::empty(); + } - ~Scoped() { - Traits::release(value); - } + ~Scoped() { Traits::release(mValue); } - // Constant getter - operator const Resource&() const { return value; } - const Resource& operator->() const { return value; } - const Resource& get() const { return value; } - // Non-constant getter. - Resource& rwget() { return value; } + // Constant getter + operator const Resource&() const { return mValue; } + const Resource& operator->() const { return mValue; } + const Resource& get() const { return mValue; } + // Non-constant getter. + Resource& rwget() { return mValue; } - /* - * Forget the resource. - * - * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will - * have no effect at destruction (unless it is reset to another resource by - * |operator=|). - * - * @return The original resource. - */ - Resource forget() { - Resource tmp = value; - value = Traits::empty(); - return tmp; - } + /* + * Forget the resource. + * + * Once |forget| has been called, the |Scoped| is neutralized, i.e. it will + * have no effect at destruction (unless it is reset to another resource by + * |operator=|). + * + * @return The original resource. + */ + Resource forget() + { + Resource tmp = mValue; + mValue = Traits::empty(); + return tmp; + } - /* - * Perform immediate clean-up of this |Scoped|. - * - * If this |Scoped| is currently empty, this method has no effect. - */ - void dispose() { - Traits::release(value); - value = Traits::empty(); - } + /* + * Perform immediate clean-up of this |Scoped|. + * + * If this |Scoped| is currently empty, this method has no effect. + */ + void dispose() + { + Traits::release(mValue); + mValue = Traits::empty(); + } - bool operator==(const Resource& other) const { - return value == other; - } + bool operator==(const Resource& aOther) const { return mValue == aOther; } - /* - * Replace the resource with another resource. - * - * Calling |operator=| has the side-effect of triggering clean-up. If you do - * not want to trigger clean-up, you should first invoke |forget|. - * - * @return this - */ - Scoped& operator=(const Resource& other) { - return reset(other); - } - Scoped& reset(const Resource& other) { - Traits::release(value); - value = other; - return *this; - } + /* + * Replace the resource with another resource. + * + * Calling |operator=| has the side-effect of triggering clean-up. If you do + * not want to trigger clean-up, you should first invoke |forget|. + * + * @return this + */ + Scoped& operator=(const Resource& aOther) { return reset(aOther); } - /* Move assignment operator. */ - Scoped& operator=(Scoped&& rhs) { - MOZ_ASSERT(&rhs != this, "self-move-assignment not allowed"); - this->~Scoped(); - new(this) Scoped(Move(rhs)); - return *this; - } + Scoped& reset(const Resource& aOther) + { + Traits::release(mValue); + mValue = aOther; + return *this; + } - private: - explicit Scoped(const Scoped& value) MOZ_DELETE; - Scoped& operator=(const Scoped& value) MOZ_DELETE; + /* Move assignment operator. */ + Scoped& operator=(Scoped&& aRhs) + { + MOZ_ASSERT(&aRhs != this, "self-move-assignment not allowed"); + this->~Scoped(); + new(this) Scoped(Move(aRhs)); + return *this; + } - private: - Resource value; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER +private: + explicit Scoped(const Scoped& aValue) MOZ_DELETE; + Scoped& operator=(const Scoped& aValue) MOZ_DELETE; + +private: + Resource mValue; + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; /* @@ -184,36 +184,38 @@ class Scoped * @param Traits A struct implementing clean-up. See the implementations * for more details. */ -#define SCOPED_TEMPLATE(name, Traits) \ -template \ -struct name : public mozilla::Scoped > \ -{ \ - typedef mozilla::Scoped > Super; \ - typedef typename Super::Resource Resource; \ - name& operator=(Resource rhs) { \ - Super::operator=(rhs); \ - return *this; \ - } \ - name& operator=(name&& rhs) { \ - Super::operator=(Move(rhs)); \ - return *this; \ - } \ - explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ - : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ - {} \ - explicit name(Resource rhs \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(rhs \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - explicit name(name&& rhs \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ - : Super(Move(rhs) \ - MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ - {} \ - private: \ - explicit name(name&) MOZ_DELETE; \ - name& operator=(name&) MOZ_DELETE; \ +#define SCOPED_TEMPLATE(name, Traits) \ +template \ +struct name : public mozilla::Scoped > \ +{ \ + typedef mozilla::Scoped > Super; \ + typedef typename Super::Resource Resource; \ + name& operator=(Resource aRhs) \ + { \ + Super::operator=(aRhs); \ + return *this; \ + } \ + name& operator=(name&& aRhs) \ + { \ + Super::operator=(Move(aRhs)); \ + return *this; \ + } \ + explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \ + : Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \ + {} \ + explicit name(Resource aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ + explicit name(name&& aRhs \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \ + : Super(Move(aRhs) \ + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \ + {} \ +private: \ + explicit name(name&) MOZ_DELETE; \ + name& operator=(name&) MOZ_DELETE; \ }; /* @@ -226,9 +228,9 @@ struct name : public mozilla::Scoped > \ template struct ScopedFreePtrTraits { - typedef T* type; - static T* empty() { return nullptr; } - static void release(T* ptr) { free(ptr); } + typedef T* type; + static T* empty() { return nullptr; } + static void release(T* aPtr) { free(aPtr); } }; SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) @@ -241,7 +243,7 @@ SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits) template struct ScopedDeletePtrTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete ptr; } + static void release(T* aPtr) { delete aPtr; } }; SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) @@ -254,7 +256,7 @@ SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits) template struct ScopedDeleteArrayTraits : public ScopedFreePtrTraits { - static void release(T* ptr) { delete [] ptr; } + static void release(T* aPtr) { delete [] aPtr; } }; SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) @@ -281,21 +283,22 @@ SCOPED_TEMPLATE(ScopedDeleteArray, ScopedDeleteArrayTraits) * } // file is closed with PR_Close here */ #define MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(name, Type, Deleter) \ -template <> inline void TypeSpecificDelete(Type * value) { Deleter(value); } \ +template <> inline void TypeSpecificDelete(Type* aValue) { Deleter(aValue); } \ typedef ::mozilla::TypeSpecificScopedPointer name; -template void TypeSpecificDelete(T * value); +template void TypeSpecificDelete(T* aValue); template struct TypeSpecificScopedPointerTraits { - typedef T* type; - static type empty() { return nullptr; } - static void release(type value) - { - if (value) - TypeSpecificDelete(value); + typedef T* type; + static type empty() { return nullptr; } + static void release(type aValue) + { + if (aValue) { + TypeSpecificDelete(aValue); } + } }; SCOPED_TEMPLATE(TypeSpecificScopedPointer, TypeSpecificScopedPointerTraits) diff --git a/mfbt/TemplateLib.h b/mfbt/TemplateLib.h index 50275fdadb0..ea12c18b2b0 100644 --- a/mfbt/TemplateLib.h +++ b/mfbt/TemplateLib.h @@ -28,19 +28,19 @@ namespace tl { template struct Min { - static const size_t value = I < J ? I : J; + static const size_t value = I < J ? I : J; }; template struct Max { - static const size_t value = I > J ? I : J; + static const size_t value = I > J ? I : J; }; /** Compute floor(log2(i)). */ template struct FloorLog2 { - static const size_t value = 1 + FloorLog2::value; + static const size_t value = 1 + FloorLog2::value; }; template<> struct FloorLog2<0> { /* Error */ }; template<> struct FloorLog2<1> { static const size_t value = 0; }; @@ -49,26 +49,26 @@ template<> struct FloorLog2<1> { static const size_t value = 0; }; template struct CeilingLog2 { - static const size_t value = FloorLog2<2 * I - 1>::value; + static const size_t value = FloorLog2<2 * I - 1>::value; }; /** Round up to the nearest power of 2. */ template struct RoundUpPow2 { - static const size_t value = size_t(1) << CeilingLog2::value; + static const size_t value = size_t(1) << CeilingLog2::value; }; template<> struct RoundUpPow2<0> { - static const size_t value = 1; + static const size_t value = 1; }; /** Compute the number of bits in the given unsigned type. */ template struct BitSize { - static const size_t value = sizeof(T) * CHAR_BIT; + static const size_t value = sizeof(T) * CHAR_BIT; }; /** @@ -78,17 +78,18 @@ struct BitSize template struct NBitMask { - // Assert the precondition. On success this evaluates to 0. Otherwise it - // triggers divide-by-zero at compile time: a guaranteed compile error in - // C++11, and usually one in C++98. Add this value to |value| to assure - // its computation. - static const size_t checkPrecondition = 0 / size_t(N < BitSize::value); - static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; + // Assert the precondition. On success this evaluates to 0. Otherwise it + // triggers divide-by-zero at compile time: a guaranteed compile error in + // C++11, and usually one in C++98. Add this value to |value| to assure + // its computation. + static const size_t checkPrecondition = + 0 / size_t(N < BitSize::value); + static const size_t value = (size_t(1) << N) - 1 + checkPrecondition; }; template<> struct NBitMask::value> { - static const size_t value = size_t(-1); + static const size_t value = size_t(-1); }; /** @@ -98,8 +99,8 @@ struct NBitMask::value> template struct MulOverflowMask { - static const size_t value = - ~NBitMask::value - CeilingLog2::value>::value; + static const size_t value = + ~NBitMask::value - CeilingLog2::value>::value; }; template<> struct MulOverflowMask<0> { /* Error */ }; template<> struct MulOverflowMask<1> { static const size_t value = 0; }; diff --git a/mfbt/ThreadLocal.h b/mfbt/ThreadLocal.h index 605661d3bcd..28015de22e2 100644 --- a/mfbt/ThreadLocal.h +++ b/mfbt/ThreadLocal.h @@ -73,30 +73,29 @@ template class ThreadLocal { #if defined(XP_WIN) - typedef unsigned long key_t; + typedef unsigned long key_t; #else - typedef pthread_key_t key_t; + typedef pthread_key_t key_t; #endif - union Helper { - void* ptr; - T value; - }; + union Helper + { + void* mPtr; + T mValue; + }; - public: - MOZ_WARN_UNUSED_RESULT inline bool init(); +public: + MOZ_WARN_UNUSED_RESULT inline bool init(); - inline T get() const; + inline T get() const; - inline void set(const T value); + inline void set(const T aValue); - bool initialized() const { - return inited; - } + bool initialized() const { return mInited; } - private: - key_t key; - bool inited; +private: + key_t mKey; + bool mInited; }; template @@ -108,12 +107,12 @@ ThreadLocal::init() "a pointer"); MOZ_ASSERT(!initialized()); #ifdef XP_WIN - key = TlsAlloc(); - inited = key != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES + mKey = TlsAlloc(); + mInited = mKey != 0xFFFFFFFFUL; // TLS_OUT_OF_INDEXES #else - inited = !pthread_key_create(&key, nullptr); + mInited = !pthread_key_create(&mKey, nullptr); #endif - return inited; + return mInited; } template @@ -123,28 +122,28 @@ ThreadLocal::get() const MOZ_ASSERT(initialized()); Helper h; #ifdef XP_WIN - h.ptr = TlsGetValue(key); + h.mPtr = TlsGetValue(mKey); #else - h.ptr = pthread_getspecific(key); + h.mPtr = pthread_getspecific(mKey); #endif - return h.value; + return h.mValue; } template inline void -ThreadLocal::set(const T value) +ThreadLocal::set(const T aValue) { MOZ_ASSERT(initialized()); Helper h; - h.value = value; - bool succeeded; + h.mValue = aValue; #ifdef XP_WIN - succeeded = TlsSetValue(key, h.ptr); + bool succeeded = TlsSetValue(mKey, h.mPtr); #else - succeeded = !pthread_setspecific(key, h.ptr); + bool succeeded = !pthread_setspecific(mKey, h.mPtr); #endif - if (!succeeded) + if (!succeeded) { MOZ_CRASH(); + } } } // namespace mozilla diff --git a/mfbt/ToString.h b/mfbt/ToString.h index baccf2c712d..f11cad5cb64 100644 --- a/mfbt/ToString.h +++ b/mfbt/ToString.h @@ -20,10 +20,10 @@ namespace mozilla { */ template std::string -ToString(const T& t) +ToString(const T& aValue) { std::ostringstream stream; - stream << t; + stream << aValue; return stream.str(); } diff --git a/mfbt/TypeTraits.h b/mfbt/TypeTraits.h index 3184221ec59..515c68d94ec 100644 --- a/mfbt/TypeTraits.h +++ b/mfbt/TypeTraits.h @@ -34,9 +34,9 @@ template struct RemoveCV; template struct IntegralConstant { - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; + static const T value = Value; + typedef T ValueType; + typedef IntegralConstant Type; }; /** Convenient aliases. */ @@ -522,35 +522,35 @@ struct BaseOfTester : IntegralConstant {}; template struct BaseOfHelper { - public: - operator Base*() const; - operator Derived*(); +public: + operator Base*() const; + operator Derived*(); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); +private: + template + static char test(Derived*, T); + static int test(Base*, int); - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template struct BaseOfTester { - private: - template - static char test(Derived*, T); - static int test(Base*, int); +private: + template + static char test(Derived*, T); + static int test(Base*, int); - public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); +public: + static const bool value = + sizeof(test(BaseOfHelper(), int())) == sizeof(char); }; template @@ -588,18 +588,18 @@ namespace detail { template struct ConvertibleTester { - private: - static From create(); +private: + static From create(); - template - static char test(To to); + template + static char test(To to); - template - static int test(...); + template + static int test(...); - public: - static const bool value = - sizeof(test(create())) == sizeof(char); +public: + static const bool value = + sizeof(test(create())) == sizeof(char); }; } // namespace detail @@ -645,13 +645,13 @@ struct IsConvertible template struct RemoveConst { - typedef T Type; + typedef T Type; }; template struct RemoveConst { - typedef T Type; + typedef T Type; }; /** @@ -665,13 +665,13 @@ struct RemoveConst template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; template struct RemoveVolatile { - typedef T Type; + typedef T Type; }; /** @@ -685,7 +685,7 @@ struct RemoveVolatile template struct RemoveCV { - typedef typename RemoveConst::Type>::Type Type; + typedef typename RemoveConst::Type>::Type Type; }; /* 20.9.7.2 Reference modifications [meta.trans.ref] */ @@ -701,19 +701,19 @@ struct RemoveCV template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template struct RemoveReference { - typedef T Type; + typedef T Type; }; template @@ -729,13 +729,13 @@ struct AddLvalueReferenceHelper; template struct AddLvalueReferenceHelper { - typedef void Type; + typedef void Type; }; template struct AddLvalueReferenceHelper { - typedef T& Type; + typedef T& Type; }; } // namespace detail @@ -804,7 +804,7 @@ struct MakeSigned; template struct MakeSigned { - typedef T Type; + typedef T Type; }; template @@ -839,7 +839,8 @@ struct MakeSigned */ template struct MakeSigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeSigned >::Type {}; @@ -872,7 +873,7 @@ struct MakeUnsigned; template struct MakeUnsigned { - typedef T Type; + typedef T Type; }; template @@ -907,7 +908,8 @@ struct MakeUnsigned */ template struct MakeUnsigned - : EnableIf::value && !IsSame::Type>::value, + : EnableIf::value && + !IsSame::Type>::value, typename detail::MakeUnsigned >::Type {}; @@ -926,19 +928,19 @@ struct MakeUnsigned template struct RemoveExtent { - typedef T Type; + typedef T Type; }; template struct RemoveExtent { - typedef T Type; + typedef T Type; }; template struct RemoveExtent { - typedef T Type; + typedef T Type; }; /* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ @@ -970,7 +972,7 @@ struct EnableIf template struct EnableIf { - typedef T Type; + typedef T Type; }; /** @@ -982,13 +984,13 @@ struct EnableIf template struct Conditional { - typedef A Type; + typedef A Type; }; template struct Conditional { - typedef B Type; + typedef B Type; }; } /* namespace mozilla */ diff --git a/mfbt/TypedEnum.h b/mfbt/TypedEnum.h index d64c724f3e1..d84cd902572 100644 --- a/mfbt/TypedEnum.h +++ b/mfbt/TypedEnum.h @@ -69,13 +69,12 @@ * in namespace scope to handle bits that can only be implemented with * namespace-scoped code. For example: * - * class FooBar { - * + * class FooBar + * { * MOZ_BEGIN_NESTED_ENUM_CLASS(Enum, int32_t) * A, * B = 6 * MOZ_END_NESTED_ENUM_CLASS(Enum) - * * }; * * MOZ_FINISH_NESTED_ENUM_CLASS(FooBar::Enum) @@ -148,28 +147,28 @@ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER1(Name) \ class Name \ { \ - public: \ - enum Enum \ - { + public: \ + enum Enum \ + { /* Two-argument form. */ # define MOZ_BEGIN_NESTED_ENUM_CLASS_HELPER2(Name, type) \ class Name \ { \ - public: \ - enum Enum MOZ_ENUM_TYPE(type) \ - { + public: \ + enum Enum MOZ_ENUM_TYPE(type) \ + { # define MOZ_END_NESTED_ENUM_CLASS(Name) \ - }; \ - Name() {} \ - MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ - template \ - explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ - MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ - explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ - : mEnum(aOther.get()) \ - {} \ - private: \ - Enum mEnum; \ + }; \ + Name() {} \ + MOZ_CONSTEXPR Name(Enum aEnum) : mEnum(aEnum) {} \ + template \ + explicit MOZ_CONSTEXPR Name(Other num) : mEnum((Enum)num) {} \ + MOZ_CONSTEXPR operator Enum() const { return mEnum; } \ + explicit MOZ_CONSTEXPR Name(const mozilla::CastableTypedEnumResult& aOther) \ + : mEnum(aOther.get()) \ + {} \ + private: \ + Enum mEnum; \ }; # define MOZ_FINISH_NESTED_ENUM_CLASS(Name) \ inline int operator+(const int&, const Name::Enum&) MOZ_DELETE; \ @@ -253,14 +252,14 @@ * * S s; * - * In this example, the second template parameter to S is meant to be of type T, - * but on non-C++11 compilers, type T is a class type, not an integer type, so - * it is not accepted as the type of a constant template parameter. One would - * then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't work either - * as T depends on template parameters (more specifically here, T _is_ a template - * parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to T::Enum, we are missing - * the required "typename" keyword. So here, MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE - * is needed. + * In this example, the second template parameter to S is meant to be of type + * T, but on non-C++11 compilers, type T is a class type, not an integer + * type, so it is not accepted as the type of a constant template parameter. + * One would then want to use MOZ_ENUM_CLASS_ENUM_TYPE(T), but that doesn't + * work either as T depends on template parameters (more specifically here, T + * _is_ a template parameter) so as MOZ_ENUM_CLASS_ENUM_TYPE(T) expands to + * T::Enum, we are missing the required "typename" keyword. So here, + * MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE is needed. */ # define MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(Name) typename Name::Enum #endif diff --git a/mfbt/TypedEnumBits.h b/mfbt/TypedEnumBits.h index 377e0aa1635..1f439f12399 100644 --- a/mfbt/TypedEnumBits.h +++ b/mfbt/TypedEnumBits.h @@ -4,7 +4,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. */ +/* + * MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS allows using a typed enum as bit flags. + */ #ifndef mozilla_TypedEnumBits_h #define mozilla_TypedEnumBits_h @@ -17,22 +19,22 @@ namespace mozilla { #define MOZ_CASTABLETYPEDENUMRESULT_BINOP(Op, OtherType, ReturnType) \ template \ MOZ_CONSTEXPR ReturnType \ -operator Op(const OtherType& e, const CastableTypedEnumResult& r) \ +operator Op(const OtherType& aE, const CastableTypedEnumResult& aR) \ { \ - return ReturnType(e Op OtherType(r)); \ + return ReturnType(aE Op OtherType(aR)); \ } \ template \ MOZ_CONSTEXPR ReturnType \ -operator Op(const CastableTypedEnumResult& r, const OtherType& e) \ +operator Op(const CastableTypedEnumResult& aR, const OtherType& aE) \ { \ - return ReturnType(OtherType(r) Op e); \ + return ReturnType(OtherType(aR) Op aE); \ } \ template \ MOZ_CONSTEXPR ReturnType \ -operator Op(const CastableTypedEnumResult& r1, \ - const CastableTypedEnumResult& r2) \ +operator Op(const CastableTypedEnumResult& aR1, \ + const CastableTypedEnumResult& aR2) \ { \ - return ReturnType(OtherType(r1) Op OtherType(r2)); \ + return ReturnType(OtherType(aR1) Op OtherType(aR2)); \ } MOZ_CASTABLETYPEDENUMRESULT_BINOP(|, E, CastableTypedEnumResult) @@ -45,18 +47,18 @@ MOZ_CASTABLETYPEDENUMRESULT_BINOP(&&, bool, bool) template MOZ_CONSTEXPR CastableTypedEnumResult -operator ~(const CastableTypedEnumResult& r) +operator ~(const CastableTypedEnumResult& aR) { - return CastableTypedEnumResult(~(E(r))); + return CastableTypedEnumResult(~(E(aR))); } #define MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(Op) \ template \ E& \ -operator Op(E& r1, \ - const CastableTypedEnumResult& r2) \ +operator Op(E& aR1, \ + const CastableTypedEnumResult& aR2) \ { \ - return r1 Op E(r2); \ + return aR1 Op E(aR2); \ } MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(&=) @@ -72,15 +74,15 @@ MOZ_CASTABLETYPEDENUMRESULT_COMPOUND_ASSIGN_OP(^=) #define MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(Op, ReturnType) \ template \ MOZ_CONSTEXPR ReturnType \ -operator Op(typename E::Enum e, const CastableTypedEnumResult& r) \ +operator Op(typename E::Enum aE, const CastableTypedEnumResult& aR) \ { \ - return ReturnType(e Op E(r)); \ + return ReturnType(aE Op E(aR)); \ } \ template \ MOZ_CONSTEXPR ReturnType \ -operator Op(const CastableTypedEnumResult& r, typename E::Enum e) \ +operator Op(const CastableTypedEnumResult& aR, typename E::Enum aE) \ { \ - return ReturnType(E(r) Op e); \ + return ReturnType(E(aR) Op aE); \ } MOZ_CASTABLETYPEDENUMRESULT_BINOP_EXTRA_NON_CXX11(|, CastableTypedEnumResult) diff --git a/mfbt/TypedEnumInternal.h b/mfbt/TypedEnumInternal.h index 23b506519f6..8c88cb589b7 100644 --- a/mfbt/TypedEnumInternal.h +++ b/mfbt/TypedEnumInternal.h @@ -74,34 +74,32 @@ namespace mozilla { template class CastableTypedEnumResult { - private: - const E mValue; +private: + const E mValue; - public: - explicit MOZ_CONSTEXPR CastableTypedEnumResult(E value) - : mValue(value) - {} +public: + explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue) + : mValue(aValue) + {} - MOZ_CONSTEXPR operator E() const { return mValue; } + MOZ_CONSTEXPR operator E() const { return mValue; } - template - MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR - operator DestinationType() const { - return DestinationType(mValue); - } + template + MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + operator DestinationType() const { return DestinationType(mValue); } - MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } + MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } #ifndef MOZ_HAVE_CXX11_STRONG_ENUMS - // This get() method is used to implement a constructor in the - // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a - // CastableTypedEnumResult. If we try to implement it using the - // above conversion operator E(), then at least clang 3.3 - // (when forced to take the non-c++11 fallback path) compiles - // this constructor to an infinite recursion. So we introduce this - // get() method, that does exactly the same as the conversion operator, - // to work around this. - MOZ_CONSTEXPR E get() const { return mValue; } + // This get() method is used to implement a constructor in the + // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a + // CastableTypedEnumResult. If we try to implement it using the + // above conversion operator E(), then at least clang 3.3 + // (when forced to take the non-c++11 fallback path) compiles + // this constructor to an infinite recursion. So we introduce this + // get() method, that does exactly the same as the conversion operator, + // to work around this. + MOZ_CONSTEXPR E get() const { return mValue; } #endif }; diff --git a/mfbt/Vector.h b/mfbt/Vector.h index 4d36aa9172a..8540caf476f 100644 --- a/mfbt/Vector.h +++ b/mfbt/Vector.h @@ -39,14 +39,13 @@ namespace detail { /* * Check that the given capacity wastes the minimal amount of space if - * allocated on the heap. This means that cap*sizeof(T) is as close to a - * power-of-two as possible. growStorageBy() is responsible for ensuring - * this. + * allocated on the heap. This means that aCapacity*sizeof(T) is as close to a + * power-of-two as possible. growStorageBy() is responsible for ensuring this. */ template -static bool CapacityHasExcessSpace(size_t cap) +static bool CapacityHasExcessSpace(size_t aCapacity) { - size_t size = cap * sizeof(T); + size_t size = aCapacity * sizeof(T); return RoundUpPow2(size) - size >= sizeof(T); } @@ -57,76 +56,90 @@ static bool CapacityHasExcessSpace(size_t cap) template struct VectorImpl { - /* Destroys constructed objects in the range [begin, end). */ - static inline void destroy(T* begin, T* end) { - MOZ_ASSERT(begin <= end); - for (T* p = begin; p < end; ++p) - p->~T(); + /* Destroys constructed objects in the range [aBegin, aEnd). */ + static inline void destroy(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + p->~T(); } + } - /* Constructs objects in the uninitialized range [begin, end). */ - static inline void initialize(T* begin, T* end) { - MOZ_ASSERT(begin <= end); - for (T* p = begin; p < end; ++p) - new(p) T(); + /* Constructs objects in the uninitialized range [aBegin, aEnd). */ + static inline void initialize(T* aBegin, T* aEnd) + { + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - /* - * Copy-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - MOZ_ASSERT(srcbeg <= srcend); - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(*p); + /* + * Copy-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(*p); } + } - /* - * Move-constructs objects in the uninitialized range - * [dst, dst+(srcend-srcbeg)) from the range [srcbeg, srcend). - */ - template - static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { - MOZ_ASSERT(srcbeg <= srcend); - for (U* p = srcbeg; p < srcend; ++p, ++dst) - new(dst) T(Move(*p)); + /* + * Move-constructs objects in the uninitialized range + * [aDst, aDst+(aSrcEnd-aSrcStart)) from the range [aSrcStart, aSrcEnd). + */ + template + static inline void moveConstruct(T* aDst, U* aSrcStart, U* aSrcEnd) + { + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + new(aDst) T(Move(*p)); } + } - /* - * Copy-constructs objects in the uninitialized range [dst, dst+n) from the - * same object u. - */ - template - static inline void copyConstructN(T* dst, size_t n, const U& u) { - for (T* end = dst + n; dst < end; ++dst) - new(dst) T(u); + /* + * Copy-constructs objects in the uninitialized range [aDst, aDst+aN) from + * the same object aU. + */ + template + static inline void copyConstructN(T* aDst, size_t aN, const U& aU) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + new(aDst) T(aU); } + } - /* - * Grows the given buffer to have capacity newCap, preserving the objects - * constructed in the range [begin, end) and updating v. Assumes that (1) - * newCap has not overflowed, and (2) multiplying newCap by sizeof(T) will - * not overflow. - */ - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - T* newbuf = reinterpret_cast(v.malloc_(newCap * sizeof(T))); - if (!newbuf) - return false; - T* dst = newbuf; - T* src = v.beginNoCheck(); - for (; src < v.endNoCheck(); ++dst, ++src) - new(dst) T(Move(*src)); - VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); - v.free_(v.mBegin); - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + /* + * 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 + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + T* newbuf = reinterpret_cast(aV.malloc_(aNewCap * sizeof(T))); + if (!newbuf) { + return false; } + T* dst = newbuf; + T* src = aV.beginNoCheck(); + for (; src < aV.endNoCheck(); ++dst, ++src) { + new(dst) T(Move(*src)); + } + VectorImpl::destroy(aV.beginNoCheck(), aV.endNoCheck()); + aV.free_(aV.mBegin); + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; /* @@ -137,60 +150,71 @@ struct VectorImpl template struct VectorImpl { - static inline void destroy(T*, T*) {} + static inline void destroy(T*, T*) {} - static inline void initialize(T* begin, T* end) { - /* - * You would think that memset would be a big win (or even break even) - * when we know T is a POD. But currently it's not. This is probably - * because |append| tends to be given small ranges and memset requires - * a function call that doesn't get inlined. - * - * memset(begin, 0, sizeof(T) * (end-begin)); - */ - MOZ_ASSERT(begin <= end); - for (T* p = begin; p < end; ++p) - new(p) T(); + static inline void initialize(T* aBegin, T* aEnd) + { + /* + * You would think that memset would be a big win (or even break even) + * when we know T is a POD. But currently it's not. This is probably + * because |append| tends to be given small ranges and memset requires + * a function call that doesn't get inlined. + * + * memset(aBegin, 0, sizeof(T) * (aEnd - aBegin)); + */ + MOZ_ASSERT(aBegin <= aEnd); + for (T* p = aBegin; p < aEnd; ++p) { + new(p) T(); } + } - template - static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { - /* - * See above memset comment. Also, notice that copyConstruct is - * currently templated (T != U), so memcpy won't work without - * requiring T == U. - * - * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); - */ - MOZ_ASSERT(srcbeg <= srcend); - for (const U* p = srcbeg; p < srcend; ++p, ++dst) - *dst = *p; + template + static inline void copyConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + /* + * See above memset comment. Also, notice that copyConstruct is + * currently templated (T != U), so memcpy won't work without + * requiring T == U. + * + * memcpy(aDst, aSrcStart, sizeof(T) * (aSrcEnd - aSrcStart)); + */ + MOZ_ASSERT(aSrcStart <= aSrcEnd); + for (const U* p = aSrcStart; p < aSrcEnd; ++p, ++aDst) { + *aDst = *p; } + } - template - static inline void moveConstruct(T* dst, const U* srcbeg, const U* srcend) { - copyConstruct(dst, srcbeg, srcend); - } + template + static inline void moveConstruct(T* aDst, + const U* aSrcStart, const U* aSrcEnd) + { + copyConstruct(aDst, aSrcStart, aSrcEnd); + } - static inline void copyConstructN(T* dst, size_t n, const T& t) { - for (T* end = dst + n; dst < end; ++dst) - *dst = t; + static inline void copyConstructN(T* aDst, size_t aN, const T& aT) + { + for (T* end = aDst + aN; aDst < end; ++aDst) { + *aDst = aT; } + } - static inline bool - growTo(VectorBase& v, size_t newCap) { - MOZ_ASSERT(!v.usingInlineStorage()); - MOZ_ASSERT(!CapacityHasExcessSpace(newCap)); - size_t oldSize = sizeof(T) * v.mCapacity; - size_t newSize = sizeof(T) * newCap; - T* newbuf = reinterpret_cast(v.realloc_(v.mBegin, oldSize, newSize)); - if (!newbuf) - return false; - v.mBegin = newbuf; - /* v.mLength is unchanged. */ - v.mCapacity = newCap; - return true; + static inline bool + growTo(VectorBase& aV, size_t aNewCap) + { + MOZ_ASSERT(!aV.usingInlineStorage()); + MOZ_ASSERT(!CapacityHasExcessSpace(aNewCap)); + size_t oldSize = sizeof(T) * aV.mCapacity; + size_t newSize = sizeof(T) * aNewCap; + T* newbuf = reinterpret_cast(aV.realloc_(aV.mBegin, oldSize, newSize)); + if (!newbuf) { + return false; } + aV.mBegin = newbuf; + /* aV.mLength is unchanged. */ + aV.mCapacity = aNewCap; + return true; + } }; } // namespace detail @@ -205,376 +229,387 @@ struct VectorImpl template class VectorBase : private AllocPolicy { - /* utilities */ + /* utilities */ - static const bool sElemIsPod = IsPod::value; - typedef detail::VectorImpl Impl; - friend struct detail::VectorImpl; + static const bool kElemIsPod = IsPod::value; + typedef detail::VectorImpl Impl; + friend struct detail::VectorImpl; - bool growStorageBy(size_t incr); - bool convertToHeapStorage(size_t newCap); + bool growStorageBy(size_t aIncr); + bool convertToHeapStorage(size_t aNewCap); - /* magic constants */ + /* magic constants */ - static const int sMaxInlineBytes = 1024; + static const int kMaxInlineBytes = 1024; - /* compute constants */ + /* compute constants */ - /* - * Consider element size to be 1 for buffer sizing if there are 0 inline - * elements. This allows us to compile when the definition of the element - * type is not visible here. - * - * Explicit specialization is only allowed at namespace scope, so in order - * to keep everything here, we use a dummy template parameter with partial - * specialization. - */ - template - struct ElemSize + /* + * Consider element size to be 1 for buffer sizing if there are 0 inline + * elements. This allows us to compile when the definition of the element + * type is not visible here. + * + * Explicit specialization is only allowed at namespace scope, so in order + * to keep everything here, we use a dummy template parameter with partial + * specialization. + */ + template + struct ElemSize + { + static const size_t value = sizeof(T); + }; + template + struct ElemSize<0, Dummy> + { + static const size_t value = 1; + }; + + static const size_t kInlineCapacity = + tl::Min::value>::value; + + /* Calculate inline buffer size; avoid 0-sized array. */ + static const size_t kInlineBytes = + tl::Max<1, kInlineCapacity * ElemSize::value>::value; + + /* member data */ + + /* + * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, + * mBegin + mLength) hold valid constructed T objects. The range [mBegin + + * mLength, mBegin + mCapacity) holds uninitialized memory. The range + * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory + * previously allocated by a call to reserve(). + */ + T* mBegin; + + /* Number of elements in the vector. */ + size_t mLength; + + /* Max number of elements storable in the vector without resizing. */ + size_t mCapacity; + +#ifdef DEBUG + /* Max elements of reserved or used space in this vector. */ + size_t mReserved; +#endif + + /* Memory used for inline storage. */ + AlignedStorage mStorage; + +#ifdef DEBUG + friend class ReentrancyGuard; + bool mEntered; +#endif + + /* private accessors */ + + bool usingInlineStorage() const + { + return mBegin == const_cast(this)->inlineStorage(); + } + + T* inlineStorage() + { + return static_cast(mStorage.addr()); + } + + T* beginNoCheck() const + { + return mBegin; + } + + T* endNoCheck() + { + return mBegin + mLength; + } + + const T* endNoCheck() const + { + return mBegin + mLength; + } + +#ifdef DEBUG + size_t reserved() const + { + MOZ_ASSERT(mReserved <= mCapacity); + MOZ_ASSERT(mLength <= mReserved); + return mReserved; + } +#endif + + /* Append operations guaranteed to succeed due to pre-reserved space. */ + template void internalAppend(U&& aU); + template + void internalAppendAll(const VectorBase& aU); + void internalAppendN(const T& aT, size_t aN); + template void internalAppend(const U* aBegin, size_t aLength); + +public: + static const size_t sMaxInlineStorage = N; + + typedef T ElementType; + + explicit VectorBase(AllocPolicy = AllocPolicy()); + explicit VectorBase(ThisVector&&); /* Move constructor. */ + ThisVector& operator=(ThisVector&&); /* Move assignment. */ + ~VectorBase(); + + /* accessors */ + + const AllocPolicy& allocPolicy() const { return *this; } + + AllocPolicy& allocPolicy() { return *this; } + + enum { InlineLength = N }; + + size_t length() const { return mLength; } + + bool empty() const { return mLength == 0; } + + size_t capacity() const { return mCapacity; } + + T* begin() + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + const T* begin() const + { + MOZ_ASSERT(!mEntered); + return mBegin; + } + + T* end() + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + const T* end() const + { + MOZ_ASSERT(!mEntered); + return mBegin + mLength; + } + + T& operator[](size_t aIndex) + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + const T& operator[](size_t aIndex) const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(aIndex < mLength); + return begin()[aIndex]; + } + + T& back() + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + const T& back() const + { + MOZ_ASSERT(!mEntered); + MOZ_ASSERT(!empty()); + return *(end() - 1); + } + + class Range + { + friend class VectorBase; + T* mCur; + T* mEnd; + Range(T* aCur, T* aEnd) + : mCur(aCur) + , mEnd(aEnd) { - static const size_t value = sizeof(T); - }; - template - struct ElemSize<0, Dummy> - { - static const size_t value = 1; - }; - - static const size_t sInlineCapacity = - tl::Min::value>::value; - - /* Calculate inline buffer size; avoid 0-sized array. */ - static const size_t sInlineBytes = - tl::Max<1, sInlineCapacity * ElemSize::value>::value; - - /* member data */ - - /* - * Pointer to the buffer, be it inline or heap-allocated. Only [mBegin, - * mBegin + mLength) hold valid constructed T objects. The range [mBegin + - * mLength, mBegin + mCapacity) holds uninitialized memory. The range - * [mBegin + mLength, mBegin + mReserved) also holds uninitialized memory - * previously allocated by a call to reserve(). - */ - T* mBegin; - - /* Number of elements in the vector. */ - size_t mLength; - - /* Max number of elements storable in the vector without resizing. */ - size_t mCapacity; - -#ifdef DEBUG - /* Max elements of reserved or used space in this vector. */ - size_t mReserved; -#endif - - /* Memory used for inline storage. */ - AlignedStorage storage; - -#ifdef DEBUG - friend class ReentrancyGuard; - bool entered; -#endif - - /* private accessors */ - - bool usingInlineStorage() const { - return mBegin == const_cast(this)->inlineStorage(); + MOZ_ASSERT(aCur <= aEnd); } - T* inlineStorage() { - return static_cast(storage.addr()); - } - - T* beginNoCheck() const { - return mBegin; - } - - T* endNoCheck() { - return mBegin + mLength; - } - - const T* endNoCheck() const { - return mBegin + mLength; - } - -#ifdef DEBUG - size_t reserved() const { - MOZ_ASSERT(mReserved <= mCapacity); - MOZ_ASSERT(mLength <= mReserved); - return mReserved; - } -#endif - - /* Append operations guaranteed to succeed due to pre-reserved space. */ - template void internalAppend(U&& u); - template - void internalAppendAll(const VectorBase& u); - void internalAppendN(const T& t, size_t n); - template void internalAppend(const U* begin, size_t length); - public: - static const size_t sMaxInlineStorage = N; + Range() {} + bool empty() const { return mCur == mEnd; } + size_t remain() const { return PointerRangeSize(mCur, mEnd); } + T& front() const { MOZ_ASSERT(!empty()); return *mCur; } + void popFront() { MOZ_ASSERT(!empty()); ++mCur; } + T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; } + }; - typedef T ElementType; + Range all() { return Range(begin(), end()); } - explicit VectorBase(AllocPolicy = AllocPolicy()); - explicit VectorBase(ThisVector&&); /* Move constructor. */ - ThisVector& operator=(ThisVector&&); /* Move assignment. */ - ~VectorBase(); + /* mutators */ - /* accessors */ + /** + * Given that the vector is empty and has no inline storage, grow to + * |capacity|. + */ + bool initCapacity(size_t aRequest); - const AllocPolicy& allocPolicy() const { - return *this; - } + /** + * If reserve(length() + N) succeeds, the N next appends are guaranteed to + * succeed. + */ + bool reserve(size_t aRequest); - AllocPolicy& allocPolicy() { - return *this; - } + /** + * Destroy elements in the range [end() - aIncr, end()). Does not deallocate + * or unreserve storage for those elements. + */ + void shrinkBy(size_t aIncr); - enum { InlineLength = N }; + /** Grow the vector by aIncr elements. */ + bool growBy(size_t aIncr); - size_t length() const { - return mLength; - } + /** Call shrinkBy or growBy based on whether newSize > length(). */ + bool resize(size_t aNewLength); - bool empty() const { - return mLength == 0; - } + /** + * Increase the length of the vector, but don't initialize the new elements + * -- leave them as uninitialized memory. + */ + bool growByUninitialized(size_t aIncr); + bool resizeUninitialized(size_t aNewLength); - size_t capacity() const { - return mCapacity; - } + /** Shorthand for shrinkBy(length()). */ + void clear(); - T* begin() { - MOZ_ASSERT(!entered); - return mBegin; - } + /** Clears and releases any heap-allocated storage. */ + void clearAndFree(); - const T* begin() const { - MOZ_ASSERT(!entered); - return mBegin; - } + /** + * If true, appending |aNeeded| elements won't reallocate elements storage. + * This *doesn't* mean that infallibleAppend may be used! You still must + * reserve the extra space, even if this method indicates that appends won't + * need to reallocate elements storage. + */ + bool canAppendWithoutRealloc(size_t aNeeded) const; - T* end() { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + /** Potentially fallible append operations. */ - const T* end() const { - MOZ_ASSERT(!entered); - return mBegin + mLength; - } + /** + * This can take either a T& or a T&&. Given a T&&, it moves |aU| into the + * vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are + * not amused.") + */ + template bool append(U&& aU); - T& operator[](size_t i) { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + template + bool appendAll(const VectorBase& aU); + bool appendN(const T& aT, size_t aN); + template bool append(const U* aBegin, const U* aEnd); + template bool append(const U* aBegin, size_t aLength); - const T& operator[](size_t i) const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(i < mLength); - return begin()[i]; - } + /* + * Guaranteed-infallible append operations for use upon vectors whose + * memory has been pre-reserved. Don't use this if you haven't reserved the + * memory! + */ + template void infallibleAppend(U&& aU) + { + internalAppend(Forward(aU)); + } + void infallibleAppendN(const T& aT, size_t aN) + { + internalAppendN(aT, aN); + } + template void infallibleAppend(const U* aBegin, const U* aEnd) + { + internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); + } + template void infallibleAppend(const U* aBegin, size_t aLength) + { + internalAppend(aBegin, aLength); + } - T& back() { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + void popBack(); - const T& back() const { - MOZ_ASSERT(!entered); - MOZ_ASSERT(!empty()); - return *(end() - 1); - } + T popCopy(); - class Range - { - friend class VectorBase; - T* cur_; - T* end_; - Range(T* cur, T* end) : cur_(cur), end_(end) { - MOZ_ASSERT(cur <= end); - } + /** + * Transfers ownership of the internal buffer used by this vector to the + * caller. (It's the caller's responsibility to properly deallocate this + * buffer, in accordance with this vector's AllocPolicy.) After this call, + * the vector is empty. Since the returned buffer may need to be allocated + * (if the elements are currently stored in-place), the call can fail, + * returning nullptr. + * + * N.B. Although a T*, only the range [0, length()) is constructed. + */ + T* extractRawBuffer(); - public: - Range() {} - bool empty() const { return cur_ == end_; } - size_t remain() const { return PointerRangeSize(cur_, end_); } - T& front() const { MOZ_ASSERT(!empty()); return *cur_; } - void popFront() { MOZ_ASSERT(!empty()); ++cur_; } - T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } - }; + /** + * Transfer ownership of an array of objects into the vector. The caller + * must have allocated the array in accordance with this vector's + * AllocPolicy. + * + * N.B. This call assumes that there are no uninitialized elements in the + * passed array. + */ + void replaceRawBuffer(T* aP, size_t aLength); - Range all() { - return Range(begin(), end()); - } + /** + * Places |aVal| at position |aP|, shifting existing elements from |aP| onward + * one position higher. On success, |aP| should not be reused because it'll + * be a dangling pointer if reallocation of the vector storage occurred; the + * return value should be used instead. On failure, nullptr is returned. + * + * Example usage: + * + * if (!(p = vec.insert(p, val))) { + * + * } + * + * + * This is inherently a linear-time operation. Be careful! + */ + template + T* insert(T* aP, U&& aVal); - /* mutators */ + /** + * Removes the element |aT|, which must fall in the bounds [begin, end), + * shifting existing elements from |aT + 1| onward one position lower. + */ + void erase(T* aT); - /** - * Given that the vector is empty and has no inline storage, grow to - * |capacity|. - */ - bool initCapacity(size_t request); + /** + * Removes the elements [|aBegin|, |aEnd|), which must fall in the bounds + * [begin, end), shifting existing elements from |aEnd + 1| onward to aBegin's + * old position. + */ + void erase(T* aBegin, T* aEnd); - /** - * If reserve(length() + N) succeeds, the N next appends are guaranteed to - * succeed. - */ - bool reserve(size_t request); + /** + * Measure the size of the vector's heap-allocated storage. + */ + size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - /** - * Destroy elements in the range [end() - incr, end()). Does not deallocate - * or unreserve storage for those elements. - */ - void shrinkBy(size_t incr); + /** + * Like sizeOfExcludingThis, but also measures the size of the vector + * object (which must be heap-allocated) itself. + */ + size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - /** Grow the vector by incr elements. */ - bool growBy(size_t incr); + void swap(ThisVector& aOther); - /** Call shrinkBy or growBy based on whether newSize > length(). */ - bool resize(size_t newLength); +private: + VectorBase(const VectorBase&) MOZ_DELETE; + void operator=(const VectorBase&) MOZ_DELETE; - /** - * Increase the length of the vector, but don't initialize the new elements - * -- leave them as uninitialized memory. - */ - bool growByUninitialized(size_t incr); - bool resizeUninitialized(size_t newLength); - - /** Shorthand for shrinkBy(length()). */ - void clear(); - - /** Clears and releases any heap-allocated storage. */ - void clearAndFree(); - - /** - * If true, appending |needed| elements won't reallocate elements storage. - * This *doesn't* mean that infallibleAppend may be used! You still must - * reserve the extra space, even if this method indicates that appends won't - * need to reallocate elements storage. - */ - bool canAppendWithoutRealloc(size_t needed) const; - - /** Potentially fallible append operations. */ - - /** - * This can take either a T& or a T&&. Given a T&&, it moves |u| into the - * vector, instead of copying it. If it fails, |u| is left unmoved. ("We are - * not amused.") - */ - template bool append(U&& u); - - template - bool appendAll(const VectorBase& u); - bool appendN(const T& t, size_t n); - template bool append(const U* begin, const U* end); - template bool append(const U* begin, size_t length); - - /* - * Guaranteed-infallible append operations for use upon vectors whose - * memory has been pre-reserved. Don't use this if you haven't reserved the - * memory! - */ - template void infallibleAppend(U&& u) { - internalAppend(Forward(u)); - } - void infallibleAppendN(const T& t, size_t n) { - internalAppendN(t, n); - } - template void infallibleAppend(const U* aBegin, const U* aEnd) { - internalAppend(aBegin, PointerRangeSize(aBegin, aEnd)); - } - template void infallibleAppend(const U* aBegin, size_t aLength) { - internalAppend(aBegin, aLength); - } - - void popBack(); - - T popCopy(); - - /** - * Transfers ownership of the internal buffer used by this vector to the - * caller. (It's the caller's responsibility to properly deallocate this - * buffer, in accordance with this vector's AllocPolicy.) After this call, - * the vector is empty. Since the returned buffer may need to be allocated - * (if the elements are currently stored in-place), the call can fail, - * returning nullptr. - * - * N.B. Although a T*, only the range [0, length()) is constructed. - */ - T* extractRawBuffer(); - - /** - * Transfer ownership of an array of objects into the vector. The caller - * must have allocated the array in accordance with this vector's - * AllocPolicy. - * - * N.B. This call assumes that there are no uninitialized elements in the - * passed array. - */ - void replaceRawBuffer(T* p, size_t length); - - /** - * Places |val| at position |p|, shifting existing elements from |p| onward - * one position higher. On success, |p| should not be reused because it'll - * be a dangling pointer if reallocation of the vector storage occurred; the - * return value should be used instead. On failure, nullptr is returned. - * - * Example usage: - * - * if (!(p = vec.insert(p, val))) - * - * - * - * This is inherently a linear-time operation. Be careful! - */ - template - T* insert(T* p, U&& val); - - /** - * Removes the element |t|, which must fall in the bounds [begin, end), - * shifting existing elements from |t + 1| onward one position lower. - */ - void erase(T* t); - - /** - * Removes the elements [|b|, |e|), which must fall in the bounds [begin, end), - * shifting existing elements from |e + 1| onward to b's old position. - */ - void erase(T* b, T *e); - - /** - * Measure the size of the vector's heap-allocated storage. - */ - size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const; - - /** - * Like sizeOfExcludingThis, but also measures the size of the vector - * object (which must be heap-allocated) itself. - */ - size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const; - - void swap(ThisVector& other); - - private: - VectorBase(const VectorBase&) MOZ_DELETE; - void operator=(const VectorBase&) MOZ_DELETE; - - /* Move-construct/assign only from our derived class, ThisVector. */ - VectorBase(VectorBase&&) MOZ_DELETE; - void operator=(VectorBase&&) MOZ_DELETE; + /* Move-construct/assign only from our derived class, ThisVector. */ + VectorBase(VectorBase&&) MOZ_DELETE; + void operator=(VectorBase&&) MOZ_DELETE; }; /* This does the re-entrancy check plus several other sanity checks. */ #define MOZ_REENTRANCY_GUARD_ET_AL \ ReentrancyGuard g(*this); \ - MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \ + MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == kInlineCapacity); \ MOZ_ASSERT(reserved() <= mCapacity); \ MOZ_ASSERT(mLength <= reserved()); \ MOZ_ASSERT(mLength <= mCapacity) @@ -583,39 +618,39 @@ class VectorBase : private AllocPolicy template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(AP ap) - : AP(ap), - mLength(0), - mCapacity(sInlineCapacity) +VectorBase::VectorBase(AP aAP) + : AP(aAP) + , mLength(0) + , mCapacity(kInlineCapacity) #ifdef DEBUG - , mReserved(sInlineCapacity), - entered(false) + , mReserved(kInlineCapacity) + , mEntered(false) #endif { - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); } /* Move constructor. */ template MOZ_ALWAYS_INLINE -VectorBase::VectorBase(TV&& rhs) - : AllocPolicy(Move(rhs)) +VectorBase::VectorBase(TV&& aRhs) + : AllocPolicy(Move(aRhs)) #ifdef DEBUG - , entered(false) + , mEntered(false) #endif { - mLength = rhs.mLength; - mCapacity = rhs.mCapacity; + mLength = aRhs.mLength; + mCapacity = aRhs.mCapacity; #ifdef DEBUG - mReserved = rhs.mReserved; + mReserved = aRhs.mReserved; #endif - if (rhs.usingInlineStorage()) { + if (aRhs.usingInlineStorage()) { /* We can't move the buffer over in this case, so copy elements. */ - mBegin = static_cast(storage.addr()); - Impl::moveConstruct(mBegin, rhs.beginNoCheck(), rhs.endNoCheck()); + mBegin = static_cast(mStorage.addr()); + Impl::moveConstruct(mBegin, aRhs.beginNoCheck(), aRhs.endNoCheck()); /* - * Leave rhs's mLength, mBegin, mCapacity, and mReserved as they are. + * Leave aRhs's mLength, mBegin, mCapacity, and mReserved as they are. * The elements in its in-line storage still need to be destroyed. */ } else { @@ -623,26 +658,25 @@ VectorBase::VectorBase(TV&& rhs) * Take src's buffer, and turn src into an empty vector using * in-line storage. */ - mBegin = rhs.mBegin; - rhs.mBegin = static_cast(rhs.storage.addr()); - rhs.mCapacity = sInlineCapacity; - rhs.mLength = 0; + mBegin = aRhs.mBegin; + aRhs.mBegin = static_cast(aRhs.mStorage.addr()); + aRhs.mCapacity = kInlineCapacity; + aRhs.mLength = 0; #ifdef DEBUG - rhs.mReserved = sInlineCapacity; + aRhs.mReserved = kInlineCapacity; #endif } } /* Move assignment. */ template -MOZ_ALWAYS_INLINE -TV& -VectorBase::operator=(TV&& rhs) +MOZ_ALWAYS_INLINE TV& +VectorBase::operator=(TV&& aRhs) { - MOZ_ASSERT(this != &rhs, "self-move assignment is prohibited"); + MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited"); TV* tv = static_cast(this); tv->~TV(); - new(tv) TV(Move(rhs)); + new(tv) TV(Move(aRhs)); return *tv; } @@ -652,26 +686,28 @@ VectorBase::~VectorBase() { MOZ_REENTRANCY_GUARD_ET_AL; Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } } /* - * This function will create a new heap buffer with capacity newCap, + * This function will create a new heap buffer with capacity aNewCap, * move all elements in the inline buffer to this new buffer, * and fail on OOM. */ template inline bool -VectorBase::convertToHeapStorage(size_t newCap) +VectorBase::convertToHeapStorage(size_t aNewCap) { MOZ_ASSERT(usingInlineStorage()); /* Allocate buffer. */ - MOZ_ASSERT(!detail::CapacityHasExcessSpace(newCap)); - T* newBuf = reinterpret_cast(this->malloc_(newCap * sizeof(T))); - if (!newBuf) + MOZ_ASSERT(!detail::CapacityHasExcessSpace(aNewCap)); + T* newBuf = reinterpret_cast(this->malloc_(aNewCap * sizeof(T))); + if (!newBuf) { return false; + } /* Copy inline elements into heap buffer. */ Impl::moveConstruct(newBuf, beginNoCheck(), endNoCheck()); @@ -680,15 +716,15 @@ VectorBase::convertToHeapStorage(size_t newCap) /* Switch in heap buffer. */ mBegin = newBuf; /* mLength is unchanged. */ - mCapacity = newCap; + mCapacity = aNewCap; return true; } template MOZ_NEVER_INLINE bool -VectorBase::growStorageBy(size_t incr) +VectorBase::growStorageBy(size_t aIncr) { - MOZ_ASSERT(mLength + incr > mCapacity); + MOZ_ASSERT(mLength + aIncr > mCapacity); MOZ_ASSERT_IF(!usingInlineStorage(), !detail::CapacityHasExcessSpace(mCapacity)); @@ -702,11 +738,11 @@ VectorBase::growStorageBy(size_t incr) size_t newCap; - if (incr == 1) { + if (aIncr == 1) { if (usingInlineStorage()) { /* This case occurs in ~70--80% of the calls to this function. */ size_t newSize = - tl::RoundUpPow2<(sInlineCapacity + 1) * sizeof(T)>::value; + tl::RoundUpPow2<(kInlineCapacity + 1) * sizeof(T)>::value; newCap = newSize / sizeof(T); goto convert; } @@ -739,13 +775,14 @@ VectorBase::growStorageBy(size_t incr) * then there might be space for one more element. */ newCap = mLength * 2; - if (detail::CapacityHasExcessSpace(newCap)) + if (detail::CapacityHasExcessSpace(newCap)) { newCap += 1; + } } else { /* This case occurs in ~2% of the calls to this function. */ - size_t newMinCap = mLength + incr; + size_t newMinCap = mLength + aIncr; - /* Did mLength + incr overflow? Will newCap * sizeof(T) overflow? */ + /* Did mLength + aIncr overflow? Will newCap * sizeof(T) overflow? */ if (newMinCap < mLength || newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::value) { @@ -759,7 +796,7 @@ VectorBase::growStorageBy(size_t incr) } if (usingInlineStorage()) { - convert: +convert: return convertToHeapStorage(newCap); } @@ -769,34 +806,37 @@ grow: template inline bool -VectorBase::initCapacity(size_t request) +VectorBase::initCapacity(size_t aRequest) { MOZ_ASSERT(empty()); MOZ_ASSERT(usingInlineStorage()); - if (request == 0) + if (aRequest == 0) { return true; - T* newbuf = reinterpret_cast(this->malloc_(request * sizeof(T))); - if (!newbuf) + } + T* newbuf = reinterpret_cast(this->malloc_(aRequest * sizeof(T))); + if (!newbuf) { return false; + } mBegin = newbuf; - mCapacity = request; + mCapacity = aRequest; #ifdef DEBUG - mReserved = request; + mReserved = aRequest; #endif return true; } template inline bool -VectorBase::reserve(size_t request) +VectorBase::reserve(size_t aRequest) { MOZ_REENTRANCY_GUARD_ET_AL; - if (request > mCapacity && !growStorageBy(request - mLength)) + if (aRequest > mCapacity && !growStorageBy(aRequest - mLength)) { return false; - + } #ifdef DEBUG - if (request > mReserved) - mReserved = request; + if (aRequest > mReserved) { + mReserved = aRequest; + } MOZ_ASSERT(mLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); #endif @@ -805,69 +845,73 @@ VectorBase::reserve(size_t request) template inline void -VectorBase::shrinkBy(size_t incr) +VectorBase::shrinkBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - MOZ_ASSERT(incr <= mLength); - Impl::destroy(endNoCheck() - incr, endNoCheck()); - mLength -= incr; + MOZ_ASSERT(aIncr <= mLength); + Impl::destroy(endNoCheck() - aIncr, endNoCheck()); + mLength -= aIncr; } template MOZ_ALWAYS_INLINE bool -VectorBase::growBy(size_t incr) +VectorBase::growBy(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - T* newend = endNoCheck() + incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + T* newend = endNoCheck() + aIncr; Impl::initialize(endNoCheck(), newend); - mLength += incr; + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::growByUninitialized(size_t incr) +VectorBase::growByUninitialized(size_t aIncr) { MOZ_REENTRANCY_GUARD_ET_AL; - if (incr > mCapacity - mLength && !growStorageBy(incr)) + if (aIncr > mCapacity - mLength && !growStorageBy(aIncr)) { return false; - - MOZ_ASSERT(mLength + incr <= mCapacity); - mLength += incr; + } + MOZ_ASSERT(mLength + aIncr <= mCapacity); + mLength += aIncr; #ifdef DEBUG - if (mLength > mReserved) + if (mLength > mReserved) { mReserved = mLength; + } #endif return true; } template inline bool -VectorBase::resize(size_t newLength) +VectorBase::resize(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growBy(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growBy(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } template MOZ_ALWAYS_INLINE bool -VectorBase::resizeUninitialized(size_t newLength) +VectorBase::resizeUninitialized(size_t aNewLength) { size_t curLength = mLength; - if (newLength > curLength) - return growByUninitialized(newLength - curLength); - shrinkBy(curLength - newLength); + if (aNewLength > curLength) { + return growByUninitialized(aNewLength - curLength); + } + shrinkBy(curLength - aNewLength); return true; } @@ -886,178 +930,186 @@ VectorBase::clearAndFree() { clear(); - if (usingInlineStorage()) + if (usingInlineStorage()) { return; - + } this->free_(beginNoCheck()); - mBegin = static_cast(storage.addr()); - mCapacity = sInlineCapacity; + mBegin = static_cast(mStorage.addr()); + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } template inline bool -VectorBase::canAppendWithoutRealloc(size_t needed) const +VectorBase::canAppendWithoutRealloc(size_t aNeeded) const { - return mLength + needed <= mCapacity; + return mLength + aNeeded <= mCapacity; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendAll(const VectorBase& other) +VectorBase::internalAppendAll( + const VectorBase& aOther) { - internalAppend(other.begin(), other.length()); + internalAppend(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(U&& u) +VectorBase::internalAppend(U&& aU) { MOZ_ASSERT(mLength + 1 <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - new(endNoCheck()) T(Forward(u)); + new(endNoCheck()) T(Forward(aU)); ++mLength; } template MOZ_ALWAYS_INLINE bool -VectorBase::appendN(const T& t, size_t needed) +VectorBase::appendN(const T& aT, size_t aNeeded) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength + needed > mCapacity && !growStorageBy(needed)) + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppendN(t, needed); + internalAppendN(aT, aNeeded); return true; } template MOZ_ALWAYS_INLINE void -VectorBase::internalAppendN(const T& t, size_t needed) +VectorBase::internalAppendN(const T& aT, size_t aNeeded) { - MOZ_ASSERT(mLength + needed <= mReserved); + MOZ_ASSERT(mLength + aNeeded <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstructN(endNoCheck(), needed, t); - mLength += needed; + Impl::copyConstructN(endNoCheck(), aNeeded, aT); + mLength += aNeeded; } template template inline T* -VectorBase::insert(T* p, U&& val) +VectorBase::insert(T* aP, U&& aVal) { - MOZ_ASSERT(begin() <= p); - MOZ_ASSERT(p <= end()); - size_t pos = p - begin(); + MOZ_ASSERT(begin() <= aP); + MOZ_ASSERT(aP <= end()); + size_t pos = aP - begin(); MOZ_ASSERT(pos <= mLength); size_t oldLength = mLength; if (pos == oldLength) { - if (!append(Forward(val))) + if (!append(Forward(aVal))) { return nullptr; + } } else { T oldBack = Move(back()); - if (!append(Move(oldBack))) /* Dup the last element. */ + if (!append(Move(oldBack))) { /* Dup the last element. */ return nullptr; - for (size_t i = oldLength; i > pos; --i) + } + for (size_t i = oldLength; i > pos; --i) { (*this)[i] = Move((*this)[i - 1]); - (*this)[pos] = Forward(val); + } + (*this)[pos] = Forward(aVal); } return begin() + pos; } template inline void -VectorBase::erase(T* it) +VectorBase::erase(T* aIt) { - MOZ_ASSERT(begin() <= it); - MOZ_ASSERT(it < end()); - while (it + 1 < end()) { - *it = Move(*(it + 1)); - ++it; + MOZ_ASSERT(begin() <= aIt); + MOZ_ASSERT(aIt < end()); + while (aIt + 1 < end()) { + *aIt = Move(*(aIt + 1)); + ++aIt; } popBack(); } template inline void -VectorBase::erase(T* b, T *e) +VectorBase::erase(T* aBegin, T* aEnd) { - MOZ_ASSERT(begin() <= b); - MOZ_ASSERT(b <= e); - MOZ_ASSERT(e <= end()); - while (e < end()) - *b++ = Move(*e++); - shrinkBy(e - b); + MOZ_ASSERT(begin() <= aBegin); + MOZ_ASSERT(aBegin <= aEnd); + MOZ_ASSERT(aEnd <= end()); + while (aEnd < end()) { + *aBegin++ = Move(*aEnd++); + } + shrinkBy(aEnd - aBegin); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U* insBegin, const U* insEnd) +VectorBase::append(const U* aInsBegin, const U* aInsEnd) { MOZ_REENTRANCY_GUARD_ET_AL; - size_t needed = PointerRangeSize(insBegin, insEnd); - if (mLength + needed > mCapacity && !growStorageBy(needed)) + size_t aNeeded = PointerRangeSize(aInsBegin, aInsEnd); + if (mLength + aNeeded > mCapacity && !growStorageBy(aNeeded)) { return false; - + } #ifdef DEBUG - if (mLength + needed > mReserved) - mReserved = mLength + needed; + if (mLength + aNeeded > mReserved) { + mReserved = mLength + aNeeded; + } #endif - internalAppend(insBegin, needed); + internalAppend(aInsBegin, aNeeded); return true; } template template MOZ_ALWAYS_INLINE void -VectorBase::internalAppend(const U* insBegin, size_t insLength) +VectorBase::internalAppend(const U* aInsBegin, size_t aInsLength) { - MOZ_ASSERT(mLength + insLength <= mReserved); + MOZ_ASSERT(mLength + aInsLength <= mReserved); MOZ_ASSERT(mReserved <= mCapacity); - Impl::copyConstruct(endNoCheck(), insBegin, insBegin + insLength); - mLength += insLength; + Impl::copyConstruct(endNoCheck(), aInsBegin, aInsBegin + aInsLength); + mLength += aInsLength; } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(U&& u) +VectorBase::append(U&& aU) { MOZ_REENTRANCY_GUARD_ET_AL; - if (mLength == mCapacity && !growStorageBy(1)) + if (mLength == mCapacity && !growStorageBy(1)) { return false; - + } #ifdef DEBUG - if (mLength + 1 > mReserved) + if (mLength + 1 > mReserved) { mReserved = mLength + 1; + } #endif - internalAppend(Forward(u)); + internalAppend(Forward(aU)); return true; } template template MOZ_ALWAYS_INLINE bool -VectorBase::appendAll(const VectorBase& other) +VectorBase::appendAll(const VectorBase& aOther) { - return append(other.begin(), other.length()); + return append(aOther.begin(), aOther.length()); } template template MOZ_ALWAYS_INLINE bool -VectorBase::append(const U *insBegin, size_t insLength) +VectorBase::append(const U* aInsBegin, size_t aInsLength) { - return append(insBegin, insBegin + insLength); + return append(aInsBegin, aInsBegin + aInsLength); } template @@ -1086,19 +1138,20 @@ VectorBase::extractRawBuffer() T* ret; if (usingInlineStorage()) { ret = reinterpret_cast(this->malloc_(mLength * sizeof(T))); - if (!ret) + if (!ret) { return nullptr; + } Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); Impl::destroy(beginNoCheck(), endNoCheck()); /* mBegin, mCapacity are unchanged. */ mLength = 0; } else { ret = mBegin; - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = 0; - mCapacity = sInlineCapacity; + mCapacity = kInlineCapacity; #ifdef DEBUG - mReserved = sInlineCapacity; + mReserved = kInlineCapacity; #endif } return ret; @@ -1106,30 +1159,31 @@ VectorBase::extractRawBuffer() template inline void -VectorBase::replaceRawBuffer(T* p, size_t aLength) +VectorBase::replaceRawBuffer(T* aP, size_t aLength) { MOZ_REENTRANCY_GUARD_ET_AL; /* Destroy what we have. */ Impl::destroy(beginNoCheck(), endNoCheck()); - if (!usingInlineStorage()) + if (!usingInlineStorage()) { this->free_(beginNoCheck()); + } /* Take in the new buffer. */ - if (aLength <= sInlineCapacity) { + if (aLength <= kInlineCapacity) { /* - * We convert to inline storage if possible, even though p might + * We convert to inline storage if possible, even though aP might * otherwise be acceptable. Maybe this behaviour should be * specifiable with an argument to this function. */ - mBegin = static_cast(storage.addr()); + mBegin = static_cast(mStorage.addr()); mLength = aLength; - mCapacity = sInlineCapacity; - Impl::moveConstruct(mBegin, p, p + aLength); - Impl::destroy(p, p + aLength); - this->free_(p); + mCapacity = kInlineCapacity; + Impl::moveConstruct(mBegin, aP, aP + aLength); + Impl::destroy(aP, aP + aLength); + this->free_(aP); } else { - mBegin = p; + mBegin = aP; mLength = aLength; mCapacity = aLength; } @@ -1140,42 +1194,42 @@ VectorBase::replaceRawBuffer(T* p, size_t aLength) template inline size_t -VectorBase::sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { - return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck()); + return usingInlineStorage() ? 0 : aMallocSizeOf(beginNoCheck()); } template inline size_t -VectorBase::sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const +VectorBase::sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf); + return aMallocSizeOf(this) + sizeOfExcludingThis(aMallocSizeOf); } template inline void -VectorBase::swap(TV& other) +VectorBase::swap(TV& aOther) { static_assert(N == 0, "still need to implement this for N != 0"); // This only works when inline storage is always empty. - if (!usingInlineStorage() && other.usingInlineStorage()) { - other.mBegin = mBegin; + if (!usingInlineStorage() && aOther.usingInlineStorage()) { + aOther.mBegin = mBegin; mBegin = inlineStorage(); - } else if (usingInlineStorage() && !other.usingInlineStorage()) { - mBegin = other.mBegin; - other.mBegin = other.inlineStorage(); - } else if (!usingInlineStorage() && !other.usingInlineStorage()) { - Swap(mBegin, other.mBegin); + } else if (usingInlineStorage() && !aOther.usingInlineStorage()) { + mBegin = aOther.mBegin; + aOther.mBegin = aOther.inlineStorage(); + } else if (!usingInlineStorage() && !aOther.usingInlineStorage()) { + Swap(mBegin, aOther.mBegin); } else { // This case is a no-op, since we'd set both to use their inline storage. } - Swap(mLength, other.mLength); - Swap(mCapacity, other.mCapacity); + Swap(mLength, aOther.mLength); + Swap(mCapacity, aOther.mCapacity); #ifdef DEBUG - Swap(mReserved, other.mReserved); + Swap(mReserved, aOther.mReserved); #endif } @@ -1206,14 +1260,15 @@ class Vector AllocPolicy, Vector > { - typedef VectorBase Base; + typedef VectorBase Base; - public: - explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} - Vector(Vector&& vec) : Base(Move(vec)) {} - Vector& operator=(Vector&& vec) { - return Base::operator=(Move(vec)); - } +public: + explicit Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} + Vector(Vector&& vec) : Base(Move(vec)) {} + Vector& operator=(Vector&& aOther) + { + return Base::operator=(Move(aOther)); + } }; } // namespace mozilla diff --git a/mfbt/WeakPtr.h b/mfbt/WeakPtr.h index 4aa447bb166..07f00bc2951 100644 --- a/mfbt/WeakPtr.h +++ b/mfbt/WeakPtr.h @@ -26,16 +26,17 @@ * * Example of usage: * - * // To have a class C support weak pointers, inherit from SupportsWeakPtr. + * // To have a class C support weak pointers, inherit from + * // SupportsWeakPtr. * class C : public SupportsWeakPtr * { - * public: - * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) - * int num; - * void act(); + * public: + * MOZ_DECLARE_REFCOUNTED_TYPENAME(C) + * int mNum; + * void act(); * }; * - * C* ptr = new C(); + * C* ptr = new C(); * * // Get weak pointers to ptr. The first time asWeakPtr is called * // a reference counted WeakReference object is created that @@ -46,7 +47,7 @@ * * // Test a weak pointer for validity before using it. * if (weak) { - * weak->num = 17; + * weak->mNum = 17; * weak->act(); * } * @@ -81,46 +82,48 @@ template class SupportsWeakPtrBase; namespace detail { -// This can live beyond the lifetime of the class derived from SupportsWeakPtrBase. +// This can live beyond the lifetime of the class derived from +// SupportsWeakPtrBase. template class WeakReference : public ::mozilla::RefCounted > { - public: - explicit WeakReference(T* p) : ptr(p) {} - T* get() const { - return ptr; - } +public: + explicit WeakReference(T* p) : mPtr(p) {} + + T* get() const { return mPtr; } #ifdef MOZ_REFCOUNTED_LEAK_CHECKING #ifdef XP_WIN #define snprintf _snprintf #endif - const char* typeName() const { - static char nameBuffer[1024]; - const char* innerType = ptr->typeName(); - // We could do fancier length checks at runtime, but innerType is - // controlled by us so we can ensure that this never causes a buffer - // overflow by this assertion. - MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < ArrayLength(nameBuffer), - "Exceedingly large type name"); - snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", innerType); - // This is usually not OK, but here we are returning a pointer to a static - // buffer which will immediately be used by the caller. - return nameBuffer; - } - size_t typeSize() const { - return sizeof(*this); - } + const char* typeName() const + { + static char nameBuffer[1024]; + const char* innerType = mPtr->typeName(); + // We could do fancier length checks at runtime, but innerType is + // controlled by us so we can ensure that this never causes a buffer + // overflow by this assertion. + MOZ_ASSERT(strlen(innerType) + sizeof("WeakReference<>") < + ArrayLength(nameBuffer), + "Exceedingly large type name"); + snprintf(nameBuffer, ArrayLength(nameBuffer), "WeakReference<%s>", + innerType); + // This is usually not OK, but here we are returning a pointer to a static + // buffer which will immediately be used by the caller. + return nameBuffer; + } + + size_t typeSize() const { return sizeof(*this); } #undef snprintf #endif - private: - friend class WeakPtrBase >; - friend class SupportsWeakPtrBase >; - void detach() { - ptr = nullptr; - } - T* ptr; +private: + friend class WeakPtrBase >; + friend class SupportsWeakPtrBase >; + + void detach() { mPtr = nullptr; } + + T* mPtr; }; } // namespace detail @@ -128,25 +131,29 @@ class WeakReference : public ::mozilla::RefCounted > template class SupportsWeakPtrBase { - public: - WeakPtrBase asWeakPtr() { - if (!weakRef) - weakRef = new WeakReference(static_cast(this)); - return WeakPtrBase(weakRef); +public: + WeakPtrBase asWeakPtr() + { + if (!weakRef) { + weakRef = new WeakReference(static_cast(this)); } + return WeakPtrBase(weakRef); + } - protected: - ~SupportsWeakPtrBase() { - static_assert(IsBaseOf, T>::value, - "T must derive from SupportsWeakPtrBase"); - if (weakRef) - weakRef->detach(); +protected: + ~SupportsWeakPtrBase() + { + static_assert(IsBaseOf, T>::value, + "T must derive from SupportsWeakPtrBase"); + if (weakRef) { + weakRef->detach(); } + } - private: - friend class WeakPtrBase; +private: + friend class WeakPtrBase; - RefPtr weakRef; + RefPtr weakRef; }; template @@ -157,42 +164,37 @@ class SupportsWeakPtr : public SupportsWeakPtrBase > template class WeakPtrBase { - public: - WeakPtrBase(const WeakPtrBase& o) : ref(o.ref) {} - // Ensure that ref is dereferenceable in the uninitialized state - WeakPtrBase() : ref(new WeakReference(nullptr)) {} +public: + WeakPtrBase(const WeakPtrBase& aOther) + : mRef(aOther.mRef) + {} - operator T*() const { - return ref->get(); - } - T& operator*() const { - return *ref->get(); - } + // Ensure that mRef is dereferenceable in the uninitialized state. + WeakPtrBase() : mRef(new WeakReference(nullptr)) {} - T* operator->() const { - return ref->get(); - } + operator T*() const { return mRef->get(); } + T& operator*() const { return *mRef->get(); } - T* get() const { - return ref->get(); - } + T* operator->() const { return mRef->get(); } - private: - friend class SupportsWeakPtrBase; + T* get() const { return mRef->get(); } - explicit WeakPtrBase(const RefPtr &o) : ref(o) {} +private: + friend class SupportsWeakPtrBase; - RefPtr ref; + explicit WeakPtrBase(const RefPtr &aOther) : mRef(aOther) {} + + RefPtr mRef; }; template class WeakPtr : public WeakPtrBase > { - typedef WeakPtrBase > Base; - public: - WeakPtr(const WeakPtr& o) : Base(o) {} - MOZ_IMPLICIT WeakPtr(const Base& o) : Base(o) {} - WeakPtr() {} + typedef WeakPtrBase > Base; +public: + WeakPtr(const WeakPtr& aOther) : Base(aOther) {} + MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {} + WeakPtr() {} }; } // namespace mozilla diff --git a/mfbt/WindowsVersion.h b/mfbt/WindowsVersion.h index 47d7d82174a..fcf24acc2e9 100644 --- a/mfbt/WindowsVersion.h +++ b/mfbt/WindowsVersion.h @@ -1,3 +1,5 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -9,117 +11,134 @@ #include #include -namespace mozilla +namespace mozilla { + +inline bool +IsWindowsVersionOrLater(uint32_t aVersion) { - inline bool - IsWindowsVersionOrLater(uint32_t aVersion) - { - static uint32_t minVersion = 0; - static uint32_t maxVersion = UINT32_MAX; + static uint32_t minVersion = 0; + static uint32_t maxVersion = UINT32_MAX; - if (minVersion >= aVersion) { - return true; - } + if (minVersion >= aVersion) { + return true; + } - if (aVersion >= maxVersion) { - return false; - } - - OSVERSIONINFOEX info; - ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - info.dwMajorVersion = aVersion >> 24; - info.dwMinorVersion = (aVersion >> 16) & 0xFF; - info.wServicePackMajor = (aVersion >> 8) & 0xFF; - info.wServicePackMinor = aVersion & 0xFF; - - DWORDLONG conditionMask = 0; - VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); - VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); - VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); - VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); - - if (VerifyVersionInfo(&info, - VER_MAJORVERSION | VER_MINORVERSION | - VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, - conditionMask)) { - minVersion = aVersion; - return true; - } - - maxVersion = aVersion; + if (aVersion >= maxVersion) { return false; } - inline bool - IsWindowsBuildOrLater(uint32_t aBuild) - { - static uint32_t minBuild = 0; - static uint32_t maxBuild = UINT32_MAX; + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + info.dwMajorVersion = aVersion >> 24; + info.dwMinorVersion = (aVersion >> 16) & 0xFF; + info.wServicePackMajor = (aVersion >> 8) & 0xFF; + info.wServicePackMinor = aVersion & 0xFF; - if (minBuild >= aBuild) { - return true; - } + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); - if (aBuild >= maxBuild) { - return false; - } - - OSVERSIONINFOEX info; - ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - info.dwBuildNumber = aBuild; - - DWORDLONG conditionMask = 0; - VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); - - if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) { - minBuild = aBuild; - return true; - } - - maxBuild = aBuild; - return false; + if (VerifyVersionInfo(&info, + VER_MAJORVERSION | VER_MINORVERSION | + VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, + conditionMask)) { + minVersion = aVersion; + return true; } - MOZ_ALWAYS_INLINE bool - IsXPSP3OrLater() - { return IsWindowsVersionOrLater(0x05010300ul); } - - MOZ_ALWAYS_INLINE bool - IsWin2003OrLater() - { return IsWindowsVersionOrLater(0x05020000ul); } - - MOZ_ALWAYS_INLINE bool - IsWin2003SP2OrLater() - { return IsWindowsVersionOrLater(0x05020200ul); } - - MOZ_ALWAYS_INLINE bool - IsVistaOrLater() - { return IsWindowsVersionOrLater(0x06000000ul); } - - MOZ_ALWAYS_INLINE bool - IsVistaSP1OrLater() - { return IsWindowsVersionOrLater(0x06000100ul); } - - MOZ_ALWAYS_INLINE bool - IsWin7OrLater() - { return IsWindowsVersionOrLater(0x06010000ul); } - - MOZ_ALWAYS_INLINE bool - IsWin7SP1OrLater() - { return IsWindowsVersionOrLater(0x06010100ul); } - - MOZ_ALWAYS_INLINE bool - IsWin8OrLater() - { return IsWindowsVersionOrLater(0x06020000ul); } - - MOZ_ALWAYS_INLINE bool - IsNotWin7PreRTM() - { - return IsWin7SP1OrLater() || !IsWin7OrLater() || - IsWindowsBuildOrLater(7600); - } + maxVersion = aVersion; + return false; } +inline bool +IsWindowsBuildOrLater(uint32_t aBuild) +{ + static uint32_t minBuild = 0; + static uint32_t maxBuild = UINT32_MAX; + + if (minBuild >= aBuild) { + return true; + } + + if (aBuild >= maxBuild) { + return false; + } + + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + info.dwBuildNumber = aBuild; + + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); + + if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) { + minBuild = aBuild; + return true; + } + + maxBuild = aBuild; + return false; +} + +MOZ_ALWAYS_INLINE bool +IsXPSP3OrLater() +{ + return IsWindowsVersionOrLater(0x05010300ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin2003OrLater() +{ + return IsWindowsVersionOrLater(0x05020000ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin2003SP2OrLater() +{ + return IsWindowsVersionOrLater(0x05020200ul); +} + +MOZ_ALWAYS_INLINE bool +IsVistaOrLater() +{ + return IsWindowsVersionOrLater(0x06000000ul); +} + +MOZ_ALWAYS_INLINE bool +IsVistaSP1OrLater() +{ + return IsWindowsVersionOrLater(0x06000100ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin7OrLater() +{ + return IsWindowsVersionOrLater(0x06010000ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin7SP1OrLater() +{ + return IsWindowsVersionOrLater(0x06010100ul); +} + +MOZ_ALWAYS_INLINE bool +IsWin8OrLater() +{ + return IsWindowsVersionOrLater(0x06020000ul); +} + +MOZ_ALWAYS_INLINE bool +IsNotWin7PreRTM() +{ + return IsWin7SP1OrLater() || !IsWin7OrLater() || + IsWindowsBuildOrLater(7600); +} + +} // namespace mozilla + #endif /* mozilla_WindowsVersion_h */ diff --git a/mfbt/tests/TestSHA1.cpp b/mfbt/tests/TestSHA1.cpp index 8f6f5490de8..364baad7e58 100644 --- a/mfbt/tests/TestSHA1.cpp +++ b/mfbt/tests/TestSHA1.cpp @@ -197,8 +197,9 @@ main() "expected-data size should be the same as the actual hash " "size"); - for (size_t i = 0; i < SHA1Sum::HashSize; i++) + for (size_t i = 0; i < SHA1Sum::kHashSize; i++) { MOZ_RELEASE_ASSERT(hash[i] == expected[i]); + } return 0; } diff --git a/mozglue/android/NativeCrypto.cpp b/mozglue/android/NativeCrypto.cpp index d080de86fd1..c5379a8f903 100644 --- a/mozglue/android/NativeCrypto.cpp +++ b/mozglue/android/NativeCrypto.cpp @@ -64,11 +64,11 @@ extern "C" JNIEXPORT jbyteArray JNICALL Java_org_mozilla_gecko_background_native env->ReleaseByteArrayElements(jstr, str, JNI_ABORT); - jbyteArray out = env->NewByteArray(SHA1Sum::HashSize); + jbyteArray out = env->NewByteArray(SHA1Sum::kHashSize); if (out == NULL) { return NULL; } - env->SetByteArrayRegion(out, 0, SHA1Sum::HashSize, (jbyte *) hashResult); + env->SetByteArrayRegion(out, 0, SHA1Sum::kHashSize, (jbyte *) hashResult); return out; } diff --git a/mozglue/linker/ElfLoader.h b/mozglue/linker/ElfLoader.h index 119507b6591..0c59974e527 100644 --- a/mozglue/linker/ElfLoader.h +++ b/mozglue/linker/ElfLoader.h @@ -78,7 +78,7 @@ template <> inline void RefCounted::Release() const; template <> inline RefCounted::~RefCounted() { - MOZ_ASSERT(refCnt == 0x7fffdead); + MOZ_ASSERT(mRefCnt == 0x7fffdead); } } /* namespace detail */ @@ -219,27 +219,27 @@ private: /** * Specialized RefCounted::Release. Under normal operation, when - * refCnt reaches 0, the LibHandle is deleted. Its refCnt is however increased - * to 1 on normal builds, and 0x7fffdead on debug builds so that the LibHandle - * can still be referenced while the destructor is executing. The refCnt is - * allowed to grow > 0x7fffdead, but not to decrease under that value, which - * would mean too many Releases from within the destructor. + * mRefCnt reaches 0, the LibHandle is deleted. Its mRefCnt is however + * increased to 1 on normal builds, and 0x7fffdead on debug builds so that the + * LibHandle can still be referenced while the destructor is executing. The + * mRefCnt is allowed to grow > 0x7fffdead, but not to decrease under that + * value, which would mean too many Releases from within the destructor. */ namespace mozilla { namespace detail { template <> inline void RefCounted::Release() const { #ifdef DEBUG - if (refCnt > 0x7fff0000) - MOZ_ASSERT(refCnt > 0x7fffdead); + if (mRefCnt > 0x7fff0000) + MOZ_ASSERT(mRefCnt > 0x7fffdead); #endif - MOZ_ASSERT(refCnt > 0); - if (refCnt > 0) { - if (0 == --refCnt) { + MOZ_ASSERT(mRefCnt > 0); + if (mRefCnt > 0) { + if (0 == --mRefCnt) { #ifdef DEBUG - refCnt = 0x7fffdead; + mRefCnt = 0x7fffdead; #else - refCnt = 1; + mRefCnt = 1; #endif delete static_cast(this); } diff --git a/netwerk/cache2/CacheFileIOManager.h b/netwerk/cache2/CacheFileIOManager.h index 477aa92c5a7..ad2c7308407 100644 --- a/netwerk/cache2/CacheFileIOManager.h +++ b/netwerk/cache2/CacheFileIOManager.h @@ -115,7 +115,7 @@ public: HandleHashKey(KeyTypePointer aKey) { MOZ_COUNT_CTOR(HandleHashKey); - mHash = (SHA1Sum::Hash*)new uint8_t[SHA1Sum::HashSize]; + mHash = (SHA1Sum::Hash*)new uint8_t[SHA1Sum::kHashSize]; memcpy(mHash, aKey, sizeof(SHA1Sum::Hash)); } HandleHashKey(const HandleHashKey& aOther)