Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1418)

Side by Side Diff: third_party/WebKit/Source/core/style/DataPersistent.h

Issue 2923333002: Generate StyleRareNonInheritedData in ComputedStyleBase. (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DataPersistent_h 5 #ifndef DataPersistent_h
6 #define DataPersistent_h 6 #define DataPersistent_h
7 7
8 #include <memory> 8 #include <memory>
9 #include "platform/heap/Handle.h" 9 #include "platform/heap/Handle.h"
10 #include "platform/wtf/Allocator.h" 10 #include "platform/wtf/Allocator.h"
(...skipping 28 matching lines...) Expand all
39 if (other.data_) 39 if (other.data_)
40 data_ = WTF::WrapUnique(new Persistent<T>(other.data_->Get())); 40 data_ = WTF::WrapUnique(new Persistent<T>(other.data_->Get()));
41 41
42 // Invalidated, subsequent mutations will happen on a new copy. 42 // Invalidated, subsequent mutations will happen on a new copy.
43 // 43 //
44 // (Clearing |m_ownCopy| will not be observable over T, hence 44 // (Clearing |m_ownCopy| will not be observable over T, hence
45 // the const_cast<> is considered acceptable here.) 45 // the const_cast<> is considered acceptable here.)
46 const_cast<DataPersistent&>(other).own_copy_ = false; 46 const_cast<DataPersistent&>(other).own_copy_ = false;
47 } 47 }
48 48
49 DataPersistent(DataPersistent&& other)
50 : data_(std::move(other.data_)), own_copy_(other.own_copy_) {
51 other.own_copy_ = false;
52 }
53
49 const T* Get() const { return data_ ? data_->Get() : nullptr; } 54 const T* Get() const { return data_ ? data_->Get() : nullptr; }
50 55
51 const T& operator*() const { return data_ ? *Get() : nullptr; } 56 const T& operator*() const { return data_ ? *Get() : nullptr; }
52 const T* operator->() const { return Get(); } 57 const T* operator->() const { return Get(); }
53 58
54 T* Access() { 59 T* Access() {
55 if (data_ && !own_copy_) { 60 if (data_ && !own_copy_) {
56 *data_ = (*data_)->Copy(); 61 *data_ = (*data_)->Copy();
57 own_copy_ = true; 62 own_copy_ = true;
58 } 63 }
(...skipping 12 matching lines...) Expand all
71 return data_->Get() == o.data_->Get() || *data_->Get() == *o.data_->Get(); 76 return data_->Get() == o.data_->Get() || *data_->Get() == *o.data_->Get();
72 } 77 }
73 78
74 bool operator!=(const DataPersistent<T>& o) const { 79 bool operator!=(const DataPersistent<T>& o) const {
75 DCHECK(data_); 80 DCHECK(data_);
76 DCHECK(o.data_); 81 DCHECK(o.data_);
77 return data_->Get() != o.data_->Get() && *data_->Get() != *o.data_->Get(); 82 return data_->Get() != o.data_->Get() && *data_->Get() != *o.data_->Get();
78 } 83 }
79 84
80 void operator=(std::nullptr_t) { data_.clear(); } 85 void operator=(std::nullptr_t) { data_.clear(); }
86 DataPersistent& operator=(DataPersistent&& other) {
87 data_ = std::move(other.data_);
88 own_copy_ = other.own_copy_;
89 other.own_copy_ = false;
90 return *this;
91 }
81 92
82 private: 93 private:
83 // Reduce size of DataPersistent<> by delaying creation of Persistent<>. 94 // Reduce size of DataPersistent<> by delaying creation of Persistent<>.
84 std::unique_ptr<Persistent<T>> data_; 95 std::unique_ptr<Persistent<T>> data_;
85 unsigned own_copy_ : 1; 96 unsigned own_copy_ : 1;
86 }; 97 };
87 98
88 } // namespace blink 99 } // namespace blink
89 100
90 #endif // DataPersistent_h 101 #endif // DataPersistent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698