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

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 24 matching lines...) Expand all
35 if (other.data_) 35 if (other.data_)
36 data_ = WTF::WrapUnique(new Persistent<T>(other.data_->Get())); 36 data_ = WTF::WrapUnique(new Persistent<T>(other.data_->Get()));
37 37
38 // Invalidated, subsequent mutations will happen on a new copy. 38 // Invalidated, subsequent mutations will happen on a new copy.
39 // 39 //
40 // (Clearing |m_ownCopy| will not be observable over T, hence 40 // (Clearing |m_ownCopy| will not be observable over T, hence
41 // the const_cast<> is considered acceptable here.) 41 // the const_cast<> is considered acceptable here.)
42 const_cast<DataPersistent&>(other).own_copy_ = false; 42 const_cast<DataPersistent&>(other).own_copy_ = false;
43 } 43 }
44 44
45 DataPersistent(DataPersistent&& other)
46 : data_(std::move(other.data_)), own_copy_(other.own_copy_) {
47 other.own_copy_ = false;
48 }
49
45 const T* Get() const { return data_ ? data_->Get() : nullptr; } 50 const T* Get() const { return data_ ? data_->Get() : nullptr; }
46 51
47 const T& operator*() const { return data_ ? *Get() : nullptr; } 52 const T& operator*() const { return data_ ? *Get() : nullptr; }
48 const T* operator->() const { return Get(); } 53 const T* operator->() const { return Get(); }
49 54
50 T* Access() { 55 T* Access() {
51 if (data_ && !own_copy_) { 56 if (data_ && !own_copy_) {
52 *data_ = (*data_)->Copy(); 57 *data_ = (*data_)->Copy();
53 own_copy_ = true; 58 own_copy_ = true;
54 } 59 }
(...skipping 12 matching lines...) Expand all
67 return data_->Get() == o.data_->Get() || *data_->Get() == *o.data_->Get(); 72 return data_->Get() == o.data_->Get() || *data_->Get() == *o.data_->Get();
68 } 73 }
69 74
70 bool operator!=(const DataPersistent<T>& o) const { 75 bool operator!=(const DataPersistent<T>& o) const {
71 DCHECK(data_); 76 DCHECK(data_);
72 DCHECK(o.data_); 77 DCHECK(o.data_);
73 return data_->Get() != o.data_->Get() && *data_->Get() != *o.data_->Get(); 78 return data_->Get() != o.data_->Get() && *data_->Get() != *o.data_->Get();
74 } 79 }
75 80
76 void operator=(std::nullptr_t) { data_.clear(); } 81 void operator=(std::nullptr_t) { data_.clear(); }
82 DataPersistent& operator=(DataPersistent&& other) {
83 data_ = std::move(other.data_);
84 own_copy_ = other.own_copy_;
85 other.own_copy_ = false;
alancutter (OOO until 2018) 2017/06/13 03:49:29 Here's one way to avoid repetition of logic: ~Dat
shend 2017/06/13 20:54:43 Lol I have no idea what that does :P, so I'll keep
86 return *this;
87 }
77 88
78 private: 89 private:
79 // Reduce size of DataPersistent<> by delaying creation of Persistent<>. 90 // Reduce size of DataPersistent<> by delaying creation of Persistent<>.
80 std::unique_ptr<Persistent<T>> data_; 91 std::unique_ptr<Persistent<T>> data_;
81 unsigned own_copy_ : 1; 92 unsigned own_copy_ : 1;
82 }; 93 };
83 94
84 } // namespace blink 95 } // namespace blink
85 96
86 #endif // DataPersistent_h 97 #endif // DataPersistent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698