Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / layout / style / AnimatedPropertyIDSet.h
blob8274f5ac22642cd390cce82fe4029e9aa526b74b
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_AnimatedPropertyIDSet_h
8 #define mozilla_AnimatedPropertyIDSet_h
10 #include "mozilla/ServoBindings.h"
12 #include "AnimatedPropertyID.h"
13 #include "nsTHashSet.h"
15 namespace mozilla {
17 class AnimatedPropertyIDSet {
18 public:
19 void AddProperty(const AnimatedPropertyID& aProperty) {
20 if (aProperty.IsCustom()) {
21 mCustomNames.Insert(aProperty.mCustomName);
22 } else {
23 mIDs.AddProperty(aProperty.mID);
27 void RemoveProperty(const AnimatedPropertyID& aProperty) {
28 if (aProperty.IsCustom()) {
29 mCustomNames.Remove(aProperty.mCustomName);
30 } else {
31 mIDs.RemoveProperty(aProperty.mID);
35 bool HasProperty(const AnimatedPropertyID& aProperty) const {
36 if (aProperty.IsCustom()) {
37 return mCustomNames.Contains(aProperty.mCustomName);
39 return mIDs.HasProperty(aProperty.mID);
42 bool Intersects(const nsCSSPropertyIDSet& aIDs) const {
43 return mIDs.Intersects(aIDs);
46 bool IsSubsetOf(const AnimatedPropertyIDSet& aOther) const {
47 if (!mIDs.IsSubsetOf(aOther.mIDs) ||
48 mCustomNames.Count() > aOther.mCustomNames.Count()) {
49 return false;
51 for (const auto& name : mCustomNames) {
52 if (!aOther.mCustomNames.Contains(name)) {
53 return false;
56 return true;
59 void AddProperties(const AnimatedPropertyIDSet& aOther) {
60 mIDs |= aOther.mIDs;
61 for (const auto& name : aOther.mCustomNames) {
62 mCustomNames.Insert(name);
66 private:
67 using CustomNameSet = nsTHashSet<RefPtr<nsAtom>>;
69 public:
70 // Iterator for use in range-based for loops
71 class Iterator {
72 public:
73 Iterator(Iterator&& aOther)
74 : mPropertySet(aOther.mPropertySet),
75 mIDIterator(std::move(aOther.mIDIterator)),
76 mCustomNameIterator(std::move(aOther.mCustomNameIterator)),
77 mPropertyID(eCSSProperty_UNKNOWN) {}
78 Iterator() = delete;
79 Iterator(const Iterator&) = delete;
80 Iterator& operator=(const Iterator&) = delete;
81 Iterator& operator=(const Iterator&&) = delete;
83 static Iterator BeginIterator(const AnimatedPropertyIDSet& aPropertySet) {
84 return Iterator(aPropertySet, aPropertySet.mIDs.begin(),
85 aPropertySet.mCustomNames.begin());
88 static Iterator EndIterator(const AnimatedPropertyIDSet& aPropertySet) {
89 return Iterator(aPropertySet, aPropertySet.mIDs.end(),
90 aPropertySet.mCustomNames.end());
93 bool operator!=(const Iterator& aOther) const {
94 return mIDIterator != aOther.mIDIterator ||
95 mCustomNameIterator != aOther.mCustomNameIterator;
98 Iterator& operator++() {
99 MOZ_ASSERT(mIDIterator != mPropertySet.mIDs.end() ||
100 mCustomNameIterator != mPropertySet.mCustomNames.end(),
101 "Should not iterate beyond end");
102 if (mIDIterator != mPropertySet.mIDs.end()) {
103 ++mIDIterator;
104 } else {
105 ++mCustomNameIterator;
107 return *this;
110 AnimatedPropertyID operator*() {
111 if (mIDIterator != mPropertySet.mIDs.end()) {
112 mPropertyID.mID = *mIDIterator;
113 mPropertyID.mCustomName = nullptr;
114 } else if (mCustomNameIterator != mPropertySet.mCustomNames.end()) {
115 mPropertyID.mID = eCSSPropertyExtra_variable;
116 mPropertyID.mCustomName = *mCustomNameIterator;
117 } else {
118 MOZ_ASSERT_UNREACHABLE("Should not dereference beyond end");
119 mPropertyID.mID = eCSSProperty_UNKNOWN;
120 mPropertyID.mCustomName = nullptr;
122 return mPropertyID;
125 private:
126 explicit Iterator(const AnimatedPropertyIDSet& aPropertySet,
127 nsCSSPropertyIDSet::Iterator aIDIterator,
128 CustomNameSet::const_iterator aCustomNameIterator)
129 : mPropertySet(aPropertySet),
130 mIDIterator(std::move(aIDIterator)),
131 mCustomNameIterator(std::move(aCustomNameIterator)),
132 mPropertyID(eCSSProperty_UNKNOWN) {}
134 const AnimatedPropertyIDSet& mPropertySet;
135 nsCSSPropertyIDSet::Iterator mIDIterator;
136 CustomNameSet::const_iterator mCustomNameIterator;
137 AnimatedPropertyID mPropertyID;
140 Iterator begin() const { return Iterator::BeginIterator(*this); }
141 Iterator end() const { return Iterator::EndIterator(*this); }
143 private:
144 nsCSSPropertyIDSet mIDs;
145 CustomNameSet mCustomNames;
148 } // namespace mozilla
150 #endif // mozilla_AnimatedPropertyIDSet_h