Commit bc9a96ef authored by Stephan Hartmann's avatar Stephan Hartmann Committed by Commit Bot

GCC: fix template specialization in TraceInCollectionTrait

GCC complains that explicit specialization in non-namespace scope
is happening for TraceImpl. Move TraceImpl implementations into
different nested classes and select implementation using
std::conditional.

Bug: 819294
Change-Id: I8feea5f2aa6e1f87daad61f496d6b53b1bbc49ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217887Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772215}
parent 5620f7bf
...@@ -241,50 +241,52 @@ struct TraceInCollectionTrait<kNoWeakHandling, ...@@ -241,50 +241,52 @@ struct TraceInCollectionTrait<kNoWeakHandling,
static void Trace(blink::Visitor* visitor, static void Trace(blink::Visitor* visitor,
const KeyValuePair<Key, Value>& self) { const KeyValuePair<Key, Value>& self) {
TraceImpl(visitor, self); TraceImpl::Trace(visitor, self);
} }
private: private:
template <bool = EphemeronHelper::is_ephemeron> struct TraceImplEphemerons {
static void TraceImpl(blink::Visitor* visitor,
const KeyValuePair<Key, Value>& self);
// Strongification of ephemerons, i.e., Weak/Strong and Strong/Weak.
template <>
static void TraceImpl<true>(blink::Visitor* visitor,
const KeyValuePair<Key, Value>& self) {
// Strongification of ephemerons, i.e., Weak/Strong and Strong/Weak. // Strongification of ephemerons, i.e., Weak/Strong and Strong/Weak.
// The helper ensures that helper.key always refers to the weak part and static void Trace(blink::Visitor* visitor,
// helper.value always refers to the dependent part. const KeyValuePair<Key, Value>& self) {
// We distinguish ephemeron from Weak/Weak and Strong/Strong to allow users // Strongification of ephemerons, i.e., Weak/Strong and Strong/Weak.
// to override visitation behavior. An example is creating a heap snapshot, // The helper ensures that helper.key always refers to the weak part and
// where it is useful to annotate values as being kept alive from keys // helper.value always refers to the dependent part.
// rather than the table. // We distinguish ephemeron from Weak/Weak and Strong/Strong to allow
EphemeronHelper helper(&self.key, &self.value); // users to override visitation behavior. An example is creating a heap
// Strongify the weak part. // snapshot, where it is useful to annotate values as being kept alive
blink::TraceCollectionIfEnabled< // from keys rather than the table.
kNoWeakHandling, typename EphemeronHelper::KeyType, EphemeronHelper helper(&self.key, &self.value);
typename EphemeronHelper::KeyTraits>::Trace(visitor, helper.key); // Strongify the weak part.
// Strongify the dependent part. blink::TraceCollectionIfEnabled<
visitor->TraceEphemeron( kNoWeakHandling, typename EphemeronHelper::KeyType,
*helper.key, helper.value, typename EphemeronHelper::KeyTraits>::Trace(visitor, helper.key);
blink::TraceCollectionIfEnabled< // Strongify the dependent part.
kNoWeakHandling, typename EphemeronHelper::ValueType, visitor->TraceEphemeron(
typename EphemeronHelper::ValueTraits>::Trace); *helper.key, helper.value,
} blink::TraceCollectionIfEnabled<
kNoWeakHandling, typename EphemeronHelper::ValueType,
typename EphemeronHelper::ValueTraits>::Trace);
}
};
template <> struct TraceImplDefault {
static void TraceImpl<false>(blink::Visitor* visitor, static void Trace(blink::Visitor* visitor,
const KeyValuePair<Key, Value>& self) { const KeyValuePair<Key, Value>& self) {
// Strongification of non-ephemeron KVP, i.e., Strong/Strong or Weak/Weak. // Strongification of non-ephemeron KVP, i.e., Strong/Strong or Weak/Weak.
// Order does not matter here. // Order does not matter here.
blink::TraceCollectionIfEnabled< blink::TraceCollectionIfEnabled<
kNoWeakHandling, Key, typename Traits::KeyTraits>::Trace(visitor, kNoWeakHandling, Key, typename Traits::KeyTraits>::Trace(visitor,
&self.key); &self.key);
blink::TraceCollectionIfEnabled< blink::TraceCollectionIfEnabled<
kNoWeakHandling, Value, kNoWeakHandling, Value,
typename Traits::ValueTraits>::Trace(visitor, &self.value); typename Traits::ValueTraits>::Trace(visitor, &self.value);
} }
};
using TraceImpl = typename std::conditional<EphemeronHelper::is_ephemeron,
TraceImplEphemerons,
TraceImplDefault>::type;
}; };
template <typename Key, typename Value, typename Traits> template <typename Key, typename Value, typename Traits>
......
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