Commit 80110972 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap,wtf: Use integral_constant instead of custom value tags

Bug: 1019191
Change-Id: I4a92d28681ce0aa6788642d96cf0d3c4e3c40fb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899999Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAnton Bikineev <bikineev@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712956}
parent edf02398
......@@ -196,8 +196,8 @@ class PLATFORM_EXPORT HeapAllocator {
template <typename T, typename Traits>
static void Trace(blink::Visitor* visitor, T& t) {
TraceCollectionIfEnabled<WTF::GetWeakHandlingFlag<T>(), T, Traits>::Trace(
visitor, &t);
TraceCollectionIfEnabled<WTF::WeakHandlingTrait<T>::value, T,
Traits>::Trace(visitor, &t);
}
template <typename T, typename VisitorDispatcher>
......
......@@ -474,10 +474,7 @@ struct IsTraceable<blink::Member<T>> {
};
template <typename T>
struct IsWeak<blink::WeakMember<T>> {
STATIC_ONLY(IsWeak);
static const bool value = true;
};
struct IsWeak<blink::WeakMember<T>> : std::true_type {};
template <typename T>
struct IsTraceable<blink::WeakMember<T>> {
......
......@@ -76,7 +76,7 @@ template <WTF::WeakHandlingFlag weakness,
typename T,
typename Traits,
bool = WTF::IsTraceableInCollectionTrait<Traits>::value,
WTF::WeakHandlingFlag = WTF::GetWeakHandlingFlag<T>()>
WTF::WeakHandlingFlag = WTF::WeakHandlingTrait<T>::value>
struct TraceCollectionIfEnabled;
template <WTF::WeakHandlingFlag weakness, typename T, typename Traits>
......@@ -586,10 +586,10 @@ struct TraceInCollectionTrait<kWeakHandling, KeyValuePair<Key, Value>, Traits> {
// (ephemeron). Order of invocation does not matter as tracing weak key or
// value does not have any side effects.
return blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<Key>(), Key,
WeakHandlingTrait<Key>::value, Key,
typename Traits::KeyTraits>::IsAlive(self.key) &&
blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<Value>(), Value,
WeakHandlingTrait<Value>::value, Value,
typename Traits::ValueTraits>::IsAlive(self.value);
}
......@@ -598,11 +598,11 @@ struct TraceInCollectionTrait<kWeakHandling, KeyValuePair<Key, Value>, Traits> {
return visitor->VisitEphemeronKeyValuePair(
helper.key, helper.value,
blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<typename EphemeronHelper::KeyType>(),
WeakHandlingTrait<typename EphemeronHelper::KeyType>::value,
typename EphemeronHelper::KeyType,
typename EphemeronHelper::KeyTraits>::Trace,
blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<typename EphemeronHelper::ValueType>(),
WeakHandlingTrait<typename EphemeronHelper::ValueType>::value,
typename EphemeronHelper::ValueType,
typename EphemeronHelper::ValueTraits>::Trace);
}
......
......@@ -2113,7 +2113,7 @@ HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::
// weakly multiple times.
Allocator::template TraceHashTableBackingWeakly<ValueType, HashTable>(
visitor, table_, &table_,
WeakProcessingHashTableHelper<GetWeakHandlingFlag<ValueType>(), Key,
WeakProcessingHashTableHelper<WeakHandlingTrait<ValueType>::value, Key,
Value, Extractor, HashFunctions, Traits,
KeyTraits, Allocator>::Process,
this);
......
......@@ -404,9 +404,8 @@ struct KeyValuePair {
};
template <typename K, typename V>
struct IsWeak<KeyValuePair<K, V>> {
static constexpr bool value = IsWeak<K>::value || IsWeak<V>::value;
};
struct IsWeak<KeyValuePair<K, V>>
: std::integral_constant<bool, IsWeak<K>::value || IsWeak<V>::value> {};
template <typename KeyTraitsArg, typename ValueTraitsArg>
struct KeyValuePairHashTraits
......
......@@ -162,9 +162,8 @@ class LinkedHashSetNode : public LinkedHashSetNodeBase {
};
template <typename T>
struct IsWeak<LinkedHashSetNode<T>> {
static constexpr bool value = IsWeak<T>::value;
};
struct IsWeak<LinkedHashSetNode<T>>
: std::integral_constant<bool, IsWeak<T>::value> {};
template <typename ValueArg,
typename HashFunctions = typename DefaultHash<ValueArg>::Hash,
......
......@@ -42,9 +42,7 @@ inline const char* GetStringWithTypeName() {
// Requires garbage collection support, so it is only safe to override in sync
// with changing garbage collection semantics.
template <typename T>
struct IsWeak {
static const bool value = false;
};
struct IsWeak : std::false_type {};
enum WeakHandlingFlag {
kNoWeakHandling,
......@@ -52,9 +50,10 @@ enum WeakHandlingFlag {
};
template <typename T>
inline constexpr WeakHandlingFlag GetWeakHandlingFlag() {
return WTF::IsWeak<T>::value ? kWeakHandling : kNoWeakHandling;
}
struct WeakHandlingTrait
: std::integral_constant<WeakHandlingFlag,
IsWeak<T>::value ? kWeakHandling
: kNoWeakHandling> {};
template <typename T, typename U>
struct IsSubclass {
......@@ -133,41 +132,30 @@ class Visitor;
namespace WTF {
template <typename T>
class IsTraceable {
typedef char YesType;
typedef struct NoType { char padding[8]; } NoType;
template <typename T, typename = void>
struct IsTraceable : std::false_type {
// Fail on incomplete types.
static_assert(sizeof(T), "incomplete type T");
};
// Note that this also checks if a superclass of V has a trace method.
template <typename V>
static YesType CheckHasTraceMethod(
V* v,
blink::Visitor* p = nullptr,
typename std::enable_if<
std::is_same<decltype(v->Trace(p)), void>::value>::type* g = nullptr);
template <typename V>
static NoType CheckHasTraceMethod(...);
// Note: This also checks if a superclass of T has a trace method.
template <typename T>
struct IsTraceable<T,
base::void_t<decltype(std::declval<T>().Trace(
std::declval<blink::Visitor*>()))>> : std::true_type {};
public:
// We add sizeof(T) to both sides here, because we want it to fail for
// incomplete types. Otherwise it just assumes that incomplete types do not
// have a trace method, which may not be true.
static const bool value = sizeof(YesType) + sizeof(T) ==
sizeof(CheckHasTraceMethod<T>(nullptr)) + sizeof(T);
};
template <typename T, typename U>
struct IsTraceable<std::pair<T, U>>
: std::integral_constant<bool,
IsTraceable<T>::value || IsTraceable<U>::value> {};
// Convenience template wrapping the IsTraceableInCollection template in
// Collection Traits. It helps make the code more readable.
template <typename Traits>
class IsTraceableInCollectionTrait {
public:
static const bool value = Traits::template IsTraceableInCollection<>::value;
};
template <typename T, typename U>
struct IsTraceable<std::pair<T, U>> {
static const bool value = IsTraceable<T>::value || IsTraceable<U>::value;
};
struct IsTraceableInCollectionTrait
: std::integral_constant<
bool,
Traits::template IsTraceableInCollection<>::value> {};
// This is used to check that DISALLOW_NEW objects are not
// stored in off-heap Vectors, HashTables etc.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment