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 { ...@@ -196,8 +196,8 @@ class PLATFORM_EXPORT HeapAllocator {
template <typename T, typename Traits> template <typename T, typename Traits>
static void Trace(blink::Visitor* visitor, T& t) { static void Trace(blink::Visitor* visitor, T& t) {
TraceCollectionIfEnabled<WTF::GetWeakHandlingFlag<T>(), T, Traits>::Trace( TraceCollectionIfEnabled<WTF::WeakHandlingTrait<T>::value, T,
visitor, &t); Traits>::Trace(visitor, &t);
} }
template <typename T, typename VisitorDispatcher> template <typename T, typename VisitorDispatcher>
......
...@@ -474,10 +474,7 @@ struct IsTraceable<blink::Member<T>> { ...@@ -474,10 +474,7 @@ struct IsTraceable<blink::Member<T>> {
}; };
template <typename T> template <typename T>
struct IsWeak<blink::WeakMember<T>> { struct IsWeak<blink::WeakMember<T>> : std::true_type {};
STATIC_ONLY(IsWeak);
static const bool value = true;
};
template <typename T> template <typename T>
struct IsTraceable<blink::WeakMember<T>> { struct IsTraceable<blink::WeakMember<T>> {
......
...@@ -76,7 +76,7 @@ template <WTF::WeakHandlingFlag weakness, ...@@ -76,7 +76,7 @@ template <WTF::WeakHandlingFlag weakness,
typename T, typename T,
typename Traits, typename Traits,
bool = WTF::IsTraceableInCollectionTrait<Traits>::value, bool = WTF::IsTraceableInCollectionTrait<Traits>::value,
WTF::WeakHandlingFlag = WTF::GetWeakHandlingFlag<T>()> WTF::WeakHandlingFlag = WTF::WeakHandlingTrait<T>::value>
struct TraceCollectionIfEnabled; struct TraceCollectionIfEnabled;
template <WTF::WeakHandlingFlag weakness, typename T, typename Traits> template <WTF::WeakHandlingFlag weakness, typename T, typename Traits>
...@@ -586,10 +586,10 @@ struct TraceInCollectionTrait<kWeakHandling, KeyValuePair<Key, Value>, Traits> { ...@@ -586,10 +586,10 @@ struct TraceInCollectionTrait<kWeakHandling, KeyValuePair<Key, Value>, Traits> {
// (ephemeron). Order of invocation does not matter as tracing weak key or // (ephemeron). Order of invocation does not matter as tracing weak key or
// value does not have any side effects. // value does not have any side effects.
return blink::TraceCollectionIfEnabled< return blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<Key>(), Key, WeakHandlingTrait<Key>::value, Key,
typename Traits::KeyTraits>::IsAlive(self.key) && typename Traits::KeyTraits>::IsAlive(self.key) &&
blink::TraceCollectionIfEnabled< blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<Value>(), Value, WeakHandlingTrait<Value>::value, Value,
typename Traits::ValueTraits>::IsAlive(self.value); typename Traits::ValueTraits>::IsAlive(self.value);
} }
...@@ -598,11 +598,11 @@ struct TraceInCollectionTrait<kWeakHandling, KeyValuePair<Key, Value>, Traits> { ...@@ -598,11 +598,11 @@ struct TraceInCollectionTrait<kWeakHandling, KeyValuePair<Key, Value>, Traits> {
return visitor->VisitEphemeronKeyValuePair( return visitor->VisitEphemeronKeyValuePair(
helper.key, helper.value, helper.key, helper.value,
blink::TraceCollectionIfEnabled< blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<typename EphemeronHelper::KeyType>(), WeakHandlingTrait<typename EphemeronHelper::KeyType>::value,
typename EphemeronHelper::KeyType, typename EphemeronHelper::KeyType,
typename EphemeronHelper::KeyTraits>::Trace, typename EphemeronHelper::KeyTraits>::Trace,
blink::TraceCollectionIfEnabled< blink::TraceCollectionIfEnabled<
GetWeakHandlingFlag<typename EphemeronHelper::ValueType>(), WeakHandlingTrait<typename EphemeronHelper::ValueType>::value,
typename EphemeronHelper::ValueType, typename EphemeronHelper::ValueType,
typename EphemeronHelper::ValueTraits>::Trace); typename EphemeronHelper::ValueTraits>::Trace);
} }
......
...@@ -2113,7 +2113,7 @@ HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>:: ...@@ -2113,7 +2113,7 @@ HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::
// weakly multiple times. // weakly multiple times.
Allocator::template TraceHashTableBackingWeakly<ValueType, HashTable>( Allocator::template TraceHashTableBackingWeakly<ValueType, HashTable>(
visitor, table_, &table_, visitor, table_, &table_,
WeakProcessingHashTableHelper<GetWeakHandlingFlag<ValueType>(), Key, WeakProcessingHashTableHelper<WeakHandlingTrait<ValueType>::value, Key,
Value, Extractor, HashFunctions, Traits, Value, Extractor, HashFunctions, Traits,
KeyTraits, Allocator>::Process, KeyTraits, Allocator>::Process,
this); this);
......
...@@ -404,9 +404,8 @@ struct KeyValuePair { ...@@ -404,9 +404,8 @@ struct KeyValuePair {
}; };
template <typename K, typename V> template <typename K, typename V>
struct IsWeak<KeyValuePair<K, V>> { struct IsWeak<KeyValuePair<K, V>>
static constexpr bool value = IsWeak<K>::value || IsWeak<V>::value; : std::integral_constant<bool, IsWeak<K>::value || IsWeak<V>::value> {};
};
template <typename KeyTraitsArg, typename ValueTraitsArg> template <typename KeyTraitsArg, typename ValueTraitsArg>
struct KeyValuePairHashTraits struct KeyValuePairHashTraits
......
...@@ -162,9 +162,8 @@ class LinkedHashSetNode : public LinkedHashSetNodeBase { ...@@ -162,9 +162,8 @@ class LinkedHashSetNode : public LinkedHashSetNodeBase {
}; };
template <typename T> template <typename T>
struct IsWeak<LinkedHashSetNode<T>> { struct IsWeak<LinkedHashSetNode<T>>
static constexpr bool value = IsWeak<T>::value; : std::integral_constant<bool, IsWeak<T>::value> {};
};
template <typename ValueArg, template <typename ValueArg,
typename HashFunctions = typename DefaultHash<ValueArg>::Hash, typename HashFunctions = typename DefaultHash<ValueArg>::Hash,
......
...@@ -42,9 +42,7 @@ inline const char* GetStringWithTypeName() { ...@@ -42,9 +42,7 @@ inline const char* GetStringWithTypeName() {
// Requires garbage collection support, so it is only safe to override in sync // Requires garbage collection support, so it is only safe to override in sync
// with changing garbage collection semantics. // with changing garbage collection semantics.
template <typename T> template <typename T>
struct IsWeak { struct IsWeak : std::false_type {};
static const bool value = false;
};
enum WeakHandlingFlag { enum WeakHandlingFlag {
kNoWeakHandling, kNoWeakHandling,
...@@ -52,9 +50,10 @@ enum WeakHandlingFlag { ...@@ -52,9 +50,10 @@ enum WeakHandlingFlag {
}; };
template <typename T> template <typename T>
inline constexpr WeakHandlingFlag GetWeakHandlingFlag() { struct WeakHandlingTrait
return WTF::IsWeak<T>::value ? kWeakHandling : kNoWeakHandling; : std::integral_constant<WeakHandlingFlag,
} IsWeak<T>::value ? kWeakHandling
: kNoWeakHandling> {};
template <typename T, typename U> template <typename T, typename U>
struct IsSubclass { struct IsSubclass {
...@@ -133,41 +132,30 @@ class Visitor; ...@@ -133,41 +132,30 @@ class Visitor;
namespace WTF { namespace WTF {
template <typename T> template <typename T, typename = void>
class IsTraceable { struct IsTraceable : std::false_type {
typedef char YesType; // Fail on incomplete types.
typedef struct NoType { char padding[8]; } NoType; static_assert(sizeof(T), "incomplete type T");
};
// Note that this also checks if a superclass of V has a trace method. // Note: This also checks if a superclass of T has a trace method.
template <typename V> template <typename T>
static YesType CheckHasTraceMethod( struct IsTraceable<T,
V* v, base::void_t<decltype(std::declval<T>().Trace(
blink::Visitor* p = nullptr, std::declval<blink::Visitor*>()))>> : std::true_type {};
typename std::enable_if<
std::is_same<decltype(v->Trace(p)), void>::value>::type* g = nullptr);
template <typename V>
static NoType CheckHasTraceMethod(...);
public: template <typename T, typename U>
// We add sizeof(T) to both sides here, because we want it to fail for struct IsTraceable<std::pair<T, U>>
// incomplete types. Otherwise it just assumes that incomplete types do not : std::integral_constant<bool,
// have a trace method, which may not be true. IsTraceable<T>::value || IsTraceable<U>::value> {};
static const bool value = sizeof(YesType) + sizeof(T) ==
sizeof(CheckHasTraceMethod<T>(nullptr)) + sizeof(T);
};
// Convenience template wrapping the IsTraceableInCollection template in // Convenience template wrapping the IsTraceableInCollection template in
// Collection Traits. It helps make the code more readable. // Collection Traits. It helps make the code more readable.
template <typename Traits> template <typename Traits>
class IsTraceableInCollectionTrait { struct IsTraceableInCollectionTrait
public: : std::integral_constant<
static const bool value = Traits::template IsTraceableInCollection<>::value; bool,
}; 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;
};
// This is used to check that DISALLOW_NEW objects are not // This is used to check that DISALLOW_NEW objects are not
// stored in off-heap Vectors, HashTables etc. // 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