blob: 8299c9df44d792914ec516891a129f8931d4fd41 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
class LiveNodeListBase;
enum NodeListInvalidationType : int;
// Weakly holds (node list, invalidation type) pairs, and allows efficient
// queries of whether nodes matching particular invalidation types are present.
// Entries are automatically removed when a node list is collected by the GC.
// Adding elements and querying are both efficient, and the data structure is
// reasonably compact (and attempts to remain so). Removal (especially manual
// removal) is somewhat expensive, but expected to be infrequent.
// It is invalid to add a (list, type) pair that is already present, or to
// remove one which is not.
class CORE_EXPORT LiveNodeListRegistry {
using Entry = std::pair<UntracedMember<const LiveNodeListBase>, unsigned>;
LiveNodeListRegistry() = default;
void Add(const LiveNodeListBase*, NodeListInvalidationType);
void Remove(const LiveNodeListBase*, NodeListInvalidationType);
bool IsEmpty() const { return mask_ == 0; }
bool ContainsInvalidationType(NodeListInvalidationType type) const {
return mask_ & MaskForInvalidationType(type);
void Trace(Visitor*);
static inline unsigned MaskForInvalidationType(
NodeListInvalidationType type) {
return 1u << type;
void RecomputeMask();
// Removes any entries corresponding to node lists which have been collected
// by the GC, and updates the mask accordingly.
void ProcessCustomWeakness(const WeakCallbackInfo&);
Vector<Entry> data_;
unsigned mask_ = 0;
} // namespace blink