Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/CachedInheritingStyles.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#ifndef mozilla_CachedInheritingStyles_h
8
#define mozilla_CachedInheritingStyles_h
9
10
#include "nsAtom.h"
11
#include "nsCOMPtr.h"
12
#include "nsTArray.h"
13
14
class nsWindowSizes;
15
16
namespace mozilla {
17
18
class ComputedStyle;
19
20
// Cache of anonymous box and lazy pseudo styles that inherit from a given style.
21
//
22
// To minimize memory footprint, the cache is word-sized with a tagged pointer
23
// If there is only one entry, it's stored inline. If there are more, they're
24
// stored in an out-of-line buffer. See bug 1429126 comment 0 and comment 1 for
25
// the measurements and rationale that influenced the design.
26
class CachedInheritingStyles
27
{
28
public:
29
  void Insert(ComputedStyle* aStyle);
30
  ComputedStyle* Lookup(nsAtom* aPseudoTag) const;
31
32
0
  CachedInheritingStyles() : mBits(0) {}
33
  ~CachedInheritingStyles()
34
0
  {
35
0
    if (IsIndirect()) {
36
0
      delete AsIndirect();
37
0
    } else if (!IsEmpty()) {
38
0
      RefPtr<ComputedStyle> ref = dont_AddRef(AsDirect());
39
0
    }
40
0
  }
41
42
  void AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const;
43
44
private:
45
  // See bug 1429126 comment 1 for the choice of four here.
46
  typedef AutoTArray<RefPtr<ComputedStyle>, 4> IndirectCache;
47
48
0
  bool IsEmpty() const { return !mBits; }
49
0
  bool IsIndirect() const { return (mBits & 1); }
50
51
  ComputedStyle* AsDirect() const
52
0
  {
53
0
    MOZ_ASSERT(!IsIndirect());
54
0
    return reinterpret_cast<ComputedStyle*>(mBits);
55
0
  }
56
57
  IndirectCache* AsIndirect() const
58
0
  {
59
0
    MOZ_ASSERT(IsIndirect());
60
0
    return reinterpret_cast<IndirectCache*>(mBits & ~1);
61
0
  }
62
63
  uintptr_t mBits;
64
};
65
66
} // namespace mozilla
67
68
#endif // mozilla_CachedInheritingStyles_h