зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1422057 - Add hash function and boilerplate for deduplicating DisplayItemClipChain via std::set. r=mstange
MozReview-Commit-ID: I2eos3vwFF0 --HG-- extra : rebase_source : 79f99ef1d7fdc9a8f65703e880c66beea9b81de0
This commit is contained in:
Родитель
a3c7786114
Коммит
12596acf72
|
@ -33,6 +33,27 @@ DisplayItemClipChain::Equal(const DisplayItemClipChain* aClip1, const DisplayIte
|
|||
Equal(aClip1->mParent, aClip2->mParent);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
DisplayItemClipChain::Hash(const DisplayItemClipChain* aClip)
|
||||
{
|
||||
if (!aClip) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We include the number of rounded rects in the hash but not their contents.
|
||||
// This is to keep the hash fast, because most clips will not have rounded
|
||||
// rects and including them will slow down the hash in the common case. Note
|
||||
// that the ::Equal check still checks the rounded rect contents, so in case
|
||||
// of hash collisions the clip chains can still be distinguished using that.
|
||||
uint32_t hash = HashGeneric(aClip->mASR, aClip->mClip.GetRoundedRectCount());
|
||||
if (aClip->mClip.HasClip()) {
|
||||
const nsRect& rect = aClip->mClip.GetClipRect();
|
||||
hash = AddToHash(hash, rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/* static */ nsCString
|
||||
DisplayItemClipChain::ToString(const DisplayItemClipChain* aClipChain)
|
||||
{
|
||||
|
|
|
@ -44,6 +44,11 @@ struct DisplayItemClipChain {
|
|||
const ActiveScrolledRoot* aASR);
|
||||
|
||||
static bool Equal(const DisplayItemClipChain* aClip1, const DisplayItemClipChain* aClip2);
|
||||
/**
|
||||
* Hash function that returns the same value for any two clips A and B
|
||||
* where Equal(A, B) is true.
|
||||
*/
|
||||
static uint32_t Hash(const DisplayItemClipChain* aClip);
|
||||
|
||||
static nsCString ToString(const DisplayItemClipChain* aClipChain);
|
||||
|
||||
|
@ -71,6 +76,26 @@ struct DisplayItemClipChain {
|
|||
mutable uint32_t mRefCount = 0;
|
||||
};
|
||||
|
||||
struct DisplayItemClipChainHasher
|
||||
{
|
||||
typedef const DisplayItemClipChain* Key;
|
||||
|
||||
std::size_t operator()(const Key& aKey) const
|
||||
{
|
||||
return DisplayItemClipChain::Hash(aKey);
|
||||
}
|
||||
};
|
||||
|
||||
struct DisplayItemClipChainEqualer
|
||||
{
|
||||
typedef const DisplayItemClipChain* Key;
|
||||
|
||||
bool operator()(const Key& lhs, const Key& rhs) const
|
||||
{
|
||||
return DisplayItemClipChain::Equal(lhs, rhs);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* DISPLAYITEMCLIPCHAIN_H_ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче