2014-06-09 19:49:18 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
/* A class holding a pair of objects that tries to conserve storage space. */
|
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
#ifndef mozilla_CompactPair_h
|
|
|
|
#define mozilla_CompactPair_h
|
2014-06-09 19:49:18 +04:00
|
|
|
|
2020-03-28 16:57:11 +03:00
|
|
|
#include <type_traits>
|
2020-09-02 20:56:35 +03:00
|
|
|
#include <tuple>
|
2020-01-20 19:18:20 +03:00
|
|
|
#include <utility>
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-06-09 19:49:18 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
enum StorageType { AsBase, AsMember };
|
|
|
|
|
|
|
|
// Optimize storage using the Empty Base Optimization -- that empty base classes
|
|
|
|
// don't take up space -- to optimize size when one or the other class is
|
|
|
|
// stateless and can be used as a base class.
|
|
|
|
//
|
2020-03-17 15:42:12 +03:00
|
|
|
// The extra conditions on storage for B are necessary so that CompactPairHelper
|
|
|
|
// won't ambiguously inherit from either A or B, such that one or the other base
|
|
|
|
// class would be inaccessible.
|
2020-03-28 16:57:11 +03:00
|
|
|
template <typename A, typename B,
|
|
|
|
detail::StorageType =
|
|
|
|
std::is_empty_v<A> ? detail::AsBase : detail::AsMember,
|
|
|
|
detail::StorageType = std::is_empty_v<B> &&
|
|
|
|
!std::is_base_of<A, B>::value &&
|
|
|
|
!std::is_base_of<B, A>::value
|
|
|
|
? detail::AsBase
|
|
|
|
: detail::AsMember>
|
2020-03-17 15:42:12 +03:00
|
|
|
struct CompactPairHelper;
|
2014-06-09 19:49:18 +04:00
|
|
|
|
|
|
|
template <typename A, typename B>
|
2020-03-17 15:42:12 +03:00
|
|
|
struct CompactPairHelper<A, B, AsMember, AsMember> {
|
2014-07-11 06:10:17 +04:00
|
|
|
protected:
|
2020-09-02 20:56:35 +03:00
|
|
|
template <typename... AArgs, std::size_t... AIndexes, typename... BArgs,
|
|
|
|
std::size_t... BIndexes>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(std::tuple<AArgs...>& aATuple,
|
|
|
|
std::tuple<BArgs...>& aBTuple,
|
|
|
|
std::index_sequence<AIndexes...>,
|
|
|
|
std::index_sequence<BIndexes...>)
|
2020-09-02 20:56:35 +03:00
|
|
|
: mFirstA(std::forward<AArgs>(std::get<AIndexes>(aATuple))...),
|
|
|
|
mSecondB(std::forward<BArgs>(std::get<BIndexes>(aBTuple))...) {}
|
|
|
|
|
|
|
|
public:
|
2014-07-11 06:10:17 +04:00
|
|
|
template <typename AArg, typename BArg>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(AArg&& aA, BArg&& aB)
|
2018-06-01 19:30:30 +03:00
|
|
|
: mFirstA(std::forward<AArg>(aA)), mSecondB(std::forward<BArg>(aB)) {}
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr A& first() { return mFirstA; }
|
|
|
|
constexpr const A& first() const { return mFirstA; }
|
|
|
|
constexpr B& second() { return mSecondB; }
|
|
|
|
constexpr const B& second() const { return mSecondB; }
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
void swap(CompactPairHelper& aOther) {
|
2020-01-20 19:17:06 +03:00
|
|
|
std::swap(mFirstA, aOther.mFirstA);
|
|
|
|
std::swap(mSecondB, aOther.mSecondB);
|
2014-07-11 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
A mFirstA;
|
|
|
|
B mSecondB;
|
2014-06-09 19:49:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
2020-03-17 15:42:12 +03:00
|
|
|
struct CompactPairHelper<A, B, AsMember, AsBase> : private B {
|
2014-07-11 06:10:17 +04:00
|
|
|
protected:
|
2020-09-02 20:56:35 +03:00
|
|
|
template <typename... AArgs, std::size_t... AIndexes, typename... BArgs,
|
|
|
|
std::size_t... BIndexes>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(std::tuple<AArgs...>& aATuple,
|
|
|
|
std::tuple<BArgs...>& aBTuple,
|
|
|
|
std::index_sequence<AIndexes...>,
|
|
|
|
std::index_sequence<BIndexes...>)
|
2020-09-02 20:56:35 +03:00
|
|
|
: B(std::forward<BArgs>(std::get<BIndexes>(aBTuple))...),
|
|
|
|
mFirstA(std::forward<AArgs>(std::get<AIndexes>(aATuple))...) {}
|
|
|
|
|
|
|
|
public:
|
2014-07-11 06:10:17 +04:00
|
|
|
template <typename AArg, typename BArg>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(AArg&& aA, BArg&& aB)
|
2018-06-01 19:30:30 +03:00
|
|
|
: B(std::forward<BArg>(aB)), mFirstA(std::forward<AArg>(aA)) {}
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr A& first() { return mFirstA; }
|
|
|
|
constexpr const A& first() const { return mFirstA; }
|
|
|
|
constexpr B& second() { return *this; }
|
|
|
|
constexpr const B& second() const { return *this; }
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
void swap(CompactPairHelper& aOther) {
|
2020-01-20 19:17:06 +03:00
|
|
|
std::swap(mFirstA, aOther.mFirstA);
|
|
|
|
std::swap(static_cast<B&>(*this), static_cast<B&>(aOther));
|
2014-07-11 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
A mFirstA;
|
2014-06-09 19:49:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
2020-03-17 15:42:12 +03:00
|
|
|
struct CompactPairHelper<A, B, AsBase, AsMember> : private A {
|
2014-07-11 06:10:17 +04:00
|
|
|
protected:
|
2020-09-02 20:56:35 +03:00
|
|
|
template <typename... AArgs, std::size_t... AIndexes, typename... BArgs,
|
|
|
|
std::size_t... BIndexes>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(std::tuple<AArgs...>& aATuple,
|
|
|
|
std::tuple<BArgs...>& aBTuple,
|
|
|
|
std::index_sequence<AIndexes...>,
|
|
|
|
std::index_sequence<BIndexes...>)
|
2020-09-02 20:56:35 +03:00
|
|
|
: A(std::forward<AArgs>(std::get<AIndexes>(aATuple))...),
|
|
|
|
mSecondB(std::forward<BArgs>(std::get<BIndexes>(aBTuple))...) {}
|
|
|
|
|
|
|
|
public:
|
2014-07-11 06:10:17 +04:00
|
|
|
template <typename AArg, typename BArg>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(AArg&& aA, BArg&& aB)
|
2018-06-01 19:30:30 +03:00
|
|
|
: A(std::forward<AArg>(aA)), mSecondB(std::forward<BArg>(aB)) {}
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr A& first() { return *this; }
|
|
|
|
constexpr const A& first() const { return *this; }
|
|
|
|
constexpr B& second() { return mSecondB; }
|
|
|
|
constexpr const B& second() const { return mSecondB; }
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
void swap(CompactPairHelper& aOther) {
|
2020-01-20 19:17:06 +03:00
|
|
|
std::swap(static_cast<A&>(*this), static_cast<A&>(aOther));
|
|
|
|
std::swap(mSecondB, aOther.mSecondB);
|
2014-07-11 06:10:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
B mSecondB;
|
2014-06-09 19:49:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
2020-03-17 15:42:12 +03:00
|
|
|
struct CompactPairHelper<A, B, AsBase, AsBase> : private A, private B {
|
2014-07-11 06:10:17 +04:00
|
|
|
protected:
|
2020-09-02 20:56:35 +03:00
|
|
|
template <typename... AArgs, std::size_t... AIndexes, typename... BArgs,
|
|
|
|
std::size_t... BIndexes>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(std::tuple<AArgs...>& aATuple,
|
|
|
|
std::tuple<BArgs...>& aBTuple,
|
|
|
|
std::index_sequence<AIndexes...>,
|
|
|
|
std::index_sequence<BIndexes...>)
|
2020-09-02 20:56:35 +03:00
|
|
|
: A(std::forward<AArgs>(std::get<AIndexes>(aATuple))...),
|
|
|
|
B(std::forward<BArgs>(std::get<BIndexes>(aBTuple))...) {}
|
|
|
|
|
|
|
|
public:
|
2014-07-11 06:10:17 +04:00
|
|
|
template <typename AArg, typename BArg>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPairHelper(AArg&& aA, BArg&& aB)
|
2018-06-01 19:30:30 +03:00
|
|
|
: A(std::forward<AArg>(aA)), B(std::forward<BArg>(aB)) {}
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr A& first() { return static_cast<A&>(*this); }
|
|
|
|
constexpr const A& first() const { return static_cast<A&>(*this); }
|
|
|
|
constexpr B& second() { return static_cast<B&>(*this); }
|
|
|
|
constexpr const B& second() const { return static_cast<B&>(*this); }
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
void swap(CompactPairHelper& aOther) {
|
2020-01-20 19:17:06 +03:00
|
|
|
std::swap(static_cast<A&>(*this), static_cast<A&>(aOther));
|
|
|
|
std::swap(static_cast<B&>(*this), static_cast<B&>(aOther));
|
2014-07-11 06:10:17 +04:00
|
|
|
}
|
2014-06-09 19:49:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
/**
|
2020-03-17 15:42:12 +03:00
|
|
|
* CompactPair is the logical concatenation of an instance of A with an instance
|
|
|
|
* B. Space is conserved when possible. Neither A nor B may be a final class.
|
|
|
|
*
|
|
|
|
* In general if space conservation is not critical is preferred to use
|
|
|
|
* std::pair.
|
2014-06-09 19:49:18 +04:00
|
|
|
*
|
|
|
|
* It's typically clearer to have individual A and B member fields. Except if
|
2020-03-17 15:42:12 +03:00
|
|
|
* you want the space-conserving qualities of CompactPair, you're probably
|
|
|
|
* better off not using this!
|
2014-06-09 19:49:18 +04:00
|
|
|
*
|
|
|
|
* No guarantees are provided about the memory layout of A and B, the order of
|
|
|
|
* initialization or destruction of A and B, and so on. (This is approximately
|
|
|
|
* required to optimize space usage.) The first/second names are merely
|
|
|
|
* conceptual!
|
|
|
|
*/
|
|
|
|
template <typename A, typename B>
|
2020-03-17 15:42:12 +03:00
|
|
|
struct CompactPair : private detail::CompactPairHelper<A, B> {
|
|
|
|
typedef typename detail::CompactPairHelper<A, B> Base;
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2020-09-02 20:56:35 +03:00
|
|
|
using Base::Base;
|
|
|
|
|
|
|
|
template <typename... AArgs, typename... BArgs>
|
2021-03-23 15:35:19 +03:00
|
|
|
constexpr CompactPair(std::piecewise_construct_t, std::tuple<AArgs...> aFirst,
|
|
|
|
std::tuple<BArgs...> aSecond)
|
2020-09-02 20:56:35 +03:00
|
|
|
: Base(aFirst, aSecond, std::index_sequence_for<AArgs...>(),
|
|
|
|
std::index_sequence_for<BArgs...>()) {}
|
2014-07-11 06:10:17 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair(CompactPair&& aOther) = default;
|
|
|
|
CompactPair(const CompactPair& aOther) = default;
|
2015-03-13 03:44:30 +03:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
CompactPair& operator=(CompactPair&& aOther) = default;
|
|
|
|
CompactPair& operator=(const CompactPair& aOther) = default;
|
2015-03-17 23:56:49 +03:00
|
|
|
|
2014-07-11 06:10:17 +04:00
|
|
|
/** The A instance. */
|
|
|
|
using Base::first;
|
|
|
|
/** The B instance. */
|
|
|
|
using Base::second;
|
|
|
|
|
|
|
|
/** Swap this pair with another pair. */
|
2020-03-17 15:42:12 +03:00
|
|
|
void swap(CompactPair& aOther) { Base::swap(aOther); }
|
2014-06-09 19:49:18 +04:00
|
|
|
};
|
|
|
|
|
2015-03-13 03:44:28 +03:00
|
|
|
/**
|
2020-03-17 15:42:12 +03:00
|
|
|
* MakeCompactPair allows you to construct a CompactPair instance using type
|
|
|
|
* inference. A call like this:
|
2015-03-13 03:44:28 +03:00
|
|
|
*
|
2020-03-17 15:42:12 +03:00
|
|
|
* MakeCompactPair(Foo(), Bar())
|
2015-03-13 03:44:28 +03:00
|
|
|
*
|
2020-03-17 15:42:12 +03:00
|
|
|
* will return a CompactPair<Foo, Bar>.
|
2015-03-13 03:44:28 +03:00
|
|
|
*/
|
|
|
|
template <typename A, typename B>
|
2020-03-28 16:57:18 +03:00
|
|
|
CompactPair<std::remove_cv_t<std::remove_reference_t<A>>,
|
|
|
|
std::remove_cv_t<std::remove_reference_t<B>>>
|
2020-03-17 15:42:12 +03:00
|
|
|
MakeCompactPair(A&& aA, B&& aB) {
|
2020-03-28 16:57:18 +03:00
|
|
|
return CompactPair<std::remove_cv_t<std::remove_reference_t<A>>,
|
|
|
|
std::remove_cv_t<std::remove_reference_t<B>>>(
|
2018-06-01 19:30:30 +03:00
|
|
|
std::forward<A>(aA), std::forward<B>(aB));
|
2015-03-13 03:44:28 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 00:57:03 +03:00
|
|
|
/**
|
|
|
|
* CompactPair equality comparison
|
|
|
|
*/
|
|
|
|
template <typename A, typename B>
|
|
|
|
bool operator==(const CompactPair<A, B>& aLhs, const CompactPair<A, B>& aRhs) {
|
|
|
|
return aLhs.first() == aRhs.first() && aLhs.second() == aRhs.second();
|
|
|
|
}
|
|
|
|
|
2014-06-09 19:49:18 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-01-20 19:17:06 +03:00
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <typename A, class B>
|
2020-03-17 15:42:12 +03:00
|
|
|
void swap(mozilla::CompactPair<A, B>& aX, mozilla::CompactPair<A, B>& aY) {
|
2020-01-20 19:17:06 +03:00
|
|
|
aX.swap(aY);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
#endif /* mozilla_CompactPair_h */
|