/src/serenity/AK/CopyOnWrite.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Andreas Kling <andreas@ladybird.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/NonnullRefPtr.h> |
10 | | |
11 | | namespace AK { |
12 | | |
13 | | template<typename T> |
14 | | class CopyOnWrite { |
15 | | public: |
16 | | CopyOnWrite() |
17 | 31.7k | : m_value(adopt_ref(*new T)) |
18 | 31.7k | { |
19 | 31.7k | } AK::CopyOnWrite<URL::URL::Data>::CopyOnWrite() Line | Count | Source | 17 | 31.7k | : m_value(adopt_ref(*new T)) | 18 | 31.7k | { | 19 | 31.7k | } |
Unexecuted instantiation: AK::CopyOnWrite<Web::CSS::StyleProperties::Data>::CopyOnWrite() |
20 | | T& mutable_value() |
21 | 35.1M | { |
22 | 35.1M | if (m_value->ref_count() > 1) |
23 | 0 | m_value = m_value->clone(); |
24 | 35.1M | return *m_value; |
25 | 35.1M | } AK::CopyOnWrite<URL::URL::Data>::mutable_value() Line | Count | Source | 21 | 35.1M | { | 22 | 35.1M | if (m_value->ref_count() > 1) | 23 | 0 | m_value = m_value->clone(); | 24 | 35.1M | return *m_value; | 25 | 35.1M | } |
Unexecuted instantiation: AK::CopyOnWrite<Web::CSS::StyleProperties::Data>::mutable_value() |
26 | 112M | T const& value() const { return *m_value; }AK::CopyOnWrite<URL::URL::Data>::value() const Line | Count | Source | 26 | 112M | T const& value() const { return *m_value; } |
Unexecuted instantiation: AK::CopyOnWrite<Web::CSS::StyleProperties::Data>::value() const |
27 | | |
28 | | operator T const&() const { return value(); } |
29 | | operator T&() { return mutable_value(); } |
30 | | |
31 | 112M | T const* operator->() const { return &value(); }AK::CopyOnWrite<URL::URL::Data>::operator->() const Line | Count | Source | 31 | 112M | T const* operator->() const { return &value(); } |
Unexecuted instantiation: AK::CopyOnWrite<Web::CSS::StyleProperties::Data>::operator->() const |
32 | 35.1M | T* operator->() { return &mutable_value(); }AK::CopyOnWrite<URL::URL::Data>::operator->() Line | Count | Source | 32 | 35.1M | T* operator->() { return &mutable_value(); } |
Unexecuted instantiation: AK::CopyOnWrite<Web::CSS::StyleProperties::Data>::operator->() |
33 | | |
34 | 0 | T const* ptr() const { return m_value.ptr(); } |
35 | | T* ptr() { return m_value.ptr(); } |
36 | | |
37 | | private: |
38 | | NonnullRefPtr<T> m_value; |
39 | | }; |
40 | | |
41 | | } |