1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_CachedInheritingStyles_h
8 #define mozilla_CachedInheritingStyles_h
18 enum class PseudoStyleType
: uint8_t;
21 // Cache of anonymous box and lazy pseudo styles that inherit from a given
24 // To minimize memory footprint, the cache is word-sized with a tagged pointer
25 // If there is only one entry, it's stored inline. If there are more, they're
26 // stored in an out-of-line buffer. See bug 1429126 comment 0 and comment 1 for
27 // the measurements and rationale that influenced the design.
28 class CachedInheritingStyles
{
30 void Insert(ComputedStyle
* aStyle
);
31 ComputedStyle
* Lookup(PseudoStyleType
) const;
33 CachedInheritingStyles() : mBits(0) {}
34 ~CachedInheritingStyles() {
37 } else if (!IsEmpty()) {
38 RefPtr
<ComputedStyle
> ref
= dont_AddRef(AsDirect());
42 void AddSizeOfIncludingThis(nsWindowSizes
& aSizes
, size_t* aCVsSize
) const;
45 // See bug 1429126 comment 1 for the choice of four here.
46 typedef AutoTArray
<RefPtr
<ComputedStyle
>, 4> IndirectCache
;
48 bool IsEmpty() const { return !mBits
; }
49 bool IsIndirect() const { return (mBits
& 1); }
51 ComputedStyle
* AsDirect() const {
52 MOZ_ASSERT(!IsIndirect());
53 return reinterpret_cast<ComputedStyle
*>(mBits
);
56 IndirectCache
* AsIndirect() const {
57 MOZ_ASSERT(IsIndirect());
58 return reinterpret_cast<IndirectCache
*>(mBits
& ~1);
64 } // namespace mozilla
66 #endif // mozilla_CachedInheritingStyles_h