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

Side by Side Diff: Source/core/css/CSSValue.h

Issue 1261763005: CSSValue Immediates: Add move operators to CSSValue and NullableCSSValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_3_tagged_pointers
Patch Set: Rebase Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 // Implicit conversion from CSSPrimitiveValue. 74 // Implicit conversion from CSSPrimitiveValue.
75 CSSValue(CSSPrimitiveValue cssPrimitiveValue) 75 CSSValue(CSSPrimitiveValue cssPrimitiveValue)
76 : m_data(static_cast<CSSValueObject*>(cssPrimitiveValue.get())) 76 : m_data(static_cast<CSSValueObject*>(cssPrimitiveValue.get()))
77 { 77 {
78 ref(); 78 ref();
79 } 79 }
80 80
81 ~CSSValue() 81 ~CSSValue()
82 { 82 {
83 deref(); 83 // Although m_data can't be null, a move constructor from NullableCSSVal ue
84 // could make it null for a short time.
85 if (m_data)
86 deref();
84 } 87 }
85 88
86 CSSValue& operator=(const CSSValue& rhs) 89 CSSValue& operator=(const CSSValue& rhs)
87 { 90 {
88 rhs.ref(); 91 rhs.ref();
89 deref(); 92 deref();
90 m_data = rhs.m_data; 93 m_data = rhs.m_data;
91 return *this; 94 return *this;
92 } 95 }
93 96
97 CSSValue& operator=(CSSValue&& rhs)
98 {
99 m_data = rhs.m_data;
100 rhs.m_data.clear();
101 return *this;
102 }
103
104 CSSValue(CSSValue&& rhs)
105 {
106 m_data = rhs.m_data;
107 }
108
94 bool operator==(const CSSValue& other) const 109 bool operator==(const CSSValue& other) const
95 { 110 {
96 if (m_data == other.m_data) 111 if (m_data == other.m_data)
97 return true; 112 return true;
98 if (!isObject() || !other.isObject()) 113 if (!isObject() || !other.isObject())
99 return false; 114 return false;
100 return m_data->equals(*other.m_data); 115 return m_data->equals(*other.m_data);
101 } 116 }
102 117
103 // TODO: Remove this and update callsites to use operator== instead. 118 // TODO: Remove this and update callsites to use operator== instead.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 ~NullableCSSValue() 277 ~NullableCSSValue()
263 { 278 {
264 deref(); 279 deref();
265 }; 280 };
266 281
267 explicit operator bool() const 282 explicit operator bool() const
268 { 283 {
269 return m_data; 284 return m_data;
270 } 285 }
271 286
287 NullableCSSValue(NullableCSSValue&& rhs)
288 {
289 m_data = rhs.m_data;
290 rhs.m_data = nullptr;
291 }
292
293 NullableCSSValue(CSSValue&& rhs)
294 {
295 m_data = rhs.m_data;
296 rhs.m_data = nullptr;
297 }
298
272 NullableCSSValue& operator=(const NullableCSSValue& rhs) 299 NullableCSSValue& operator=(const NullableCSSValue& rhs)
273 { 300 {
274 rhs.ref(); 301 rhs.ref();
275 deref(); 302 deref();
276 m_data = rhs.m_data; 303 m_data = rhs.m_data;
277 return *this; 304 return *this;
278 } 305 }
279 306
307 NullableCSSValue& operator=(NullableCSSValue&& rhs)
308 {
309 m_data = rhs.m_data;
310 rhs.m_data.clear();
311 return *this;
312 }
313
280 bool operator==(const NullableCSSValue& rhs) const 314 bool operator==(const NullableCSSValue& rhs) const
281 { 315 {
282 if (m_data == rhs.m_data) 316 if (m_data == rhs.m_data)
283 return true; 317 return true;
284 if (!isObject() || (rhs && !rhs.isObject())) 318 if (!isObject() || (rhs && !rhs.isObject()))
285 return false; 319 return false;
286 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_ data); 320 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_ data);
287 } 321 }
288 322
289 bool operator!=(const NullableCSSValue& rhs) const 323 bool operator!=(const NullableCSSValue& rhs) const
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue()); 436 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue());
403 return CSSPrimitiveValue(static_cast<CSSPrimitiveValue::CSSLargePrimitiveVal ue*>(value.get())); 437 return CSSPrimitiveValue(static_cast<CSSPrimitiveValue::CSSLargePrimitiveVal ue*>(value.get()));
404 } 438 }
405 439
406 } // namespace blink 440 } // namespace blink
407 441
408 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue); 442 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue);
409 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue); 443 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue);
410 444
411 #endif // CSSValue_h 445 #endif // CSSValue_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698