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

Side by Side Diff: third_party/WebKit/Source/wtf/VectorTraits.h

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #ifndef WTF_VectorTraits_h 21 #ifndef WTF_VectorTraits_h
22 #define WTF_VectorTraits_h 22 #define WTF_VectorTraits_h
23 23
24 #include "wtf/OwnPtr.h"
25 #include "wtf/RefPtr.h" 24 #include "wtf/RefPtr.h"
26 #include "wtf/TypeTraits.h" 25 #include "wtf/TypeTraits.h"
26 #include <memory>
27 #include <type_traits> 27 #include <type_traits>
28 #include <utility> 28 #include <utility>
29 29
30 namespace WTF { 30 namespace WTF {
31 31
32 class AtomicString; 32 class AtomicString;
33 33
34 template <typename T> 34 template <typename T>
35 struct VectorTraitsBase { 35 struct VectorTraitsBase {
36 static const bool needsDestruction = !IsTriviallyDestructible<T>::value; 36 static const bool needsDestruction = !IsTriviallyDestructible<T>::value;
(...skipping 24 matching lines...) Expand all
61 // instead of constructors, copy operators, etc for initialization, move and 61 // instead of constructors, copy operators, etc for initialization, move and
62 // comparison. 62 // comparison.
63 template <typename T> 63 template <typename T>
64 struct SimpleClassVectorTraits : VectorTraitsBase<T> { 64 struct SimpleClassVectorTraits : VectorTraitsBase<T> {
65 static const bool canInitializeWithMemset = true; 65 static const bool canInitializeWithMemset = true;
66 static const bool canClearUnusedSlotsWithMemset = true; 66 static const bool canClearUnusedSlotsWithMemset = true;
67 static const bool canMoveWithMemcpy = true; 67 static const bool canMoveWithMemcpy = true;
68 static const bool canCompareWithMemcmp = true; 68 static const bool canCompareWithMemcmp = true;
69 }; 69 };
70 70
71 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and moving 71 // We know std::unique_ptr and RefPtr are simple enough that initializing to 0 a nd moving
72 // with memcpy (and then not destructing the original) will totally work. 72 // with memcpy (and then not destructing the original) will totally work.
73 template <typename P> 73 template <typename P>
74 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> {}; 74 struct VectorTraits<RefPtr<P>> : SimpleClassVectorTraits<RefPtr<P>> {};
75 75
76 template <typename P> 76 template <typename P>
77 struct VectorTraits<OwnPtr<P>> : SimpleClassVectorTraits<OwnPtr<P>> { 77 struct VectorTraits<std::unique_ptr<P>> : SimpleClassVectorTraits<std::unique_pt r<P>> {
78 // OwnPtr -> PassOwnPtr has a very particular structure that tricks the 78 // std::unique_ptr -> std::unique_ptr has a very particular structure that t ricks the
79 // normal type traits into thinking that the class is "trivially copyable". 79 // normal type traits into thinking that the class is "trivially copyable".
80 static const bool canCopyWithMemcpy = false; 80 static const bool canCopyWithMemcpy = false;
81 }; 81 };
82 static_assert(VectorTraits<RefPtr<int>>::canInitializeWithMemset, "inefficient R efPtr Vector"); 82 static_assert(VectorTraits<RefPtr<int>>::canInitializeWithMemset, "inefficient R efPtr Vector");
83 static_assert(VectorTraits<RefPtr<int>>::canMoveWithMemcpy, "inefficient RefPtr Vector"); 83 static_assert(VectorTraits<RefPtr<int>>::canMoveWithMemcpy, "inefficient RefPtr Vector");
84 static_assert(VectorTraits<RefPtr<int>>::canCompareWithMemcmp, "inefficient RefP tr Vector"); 84 static_assert(VectorTraits<RefPtr<int>>::canCompareWithMemcmp, "inefficient RefP tr Vector");
85 static_assert(VectorTraits<OwnPtr<int>>::canInitializeWithMemset, "inefficient O wnPtr Vector"); 85 static_assert(VectorTraits<std::unique_ptr<int>>::canInitializeWithMemset, "inef ficient std::unique_ptr Vector");
86 static_assert(VectorTraits<OwnPtr<int>>::canMoveWithMemcpy, "inefficient OwnPtr Vector"); 86 static_assert(VectorTraits<std::unique_ptr<int>>::canMoveWithMemcpy, "inefficien t std::unique_ptr Vector");
87 static_assert(VectorTraits<OwnPtr<int>>::canCompareWithMemcmp, "inefficient OwnP tr Vector"); 87 static_assert(VectorTraits<std::unique_ptr<int>>::canCompareWithMemcmp, "ineffic ient std::unique_ptr Vector");
88 88
89 template <typename First, typename Second> 89 template <typename First, typename Second>
90 struct VectorTraits<std::pair<First, Second>> { 90 struct VectorTraits<std::pair<First, Second>> {
91 typedef VectorTraits<First> FirstTraits; 91 typedef VectorTraits<First> FirstTraits;
92 typedef VectorTraits<Second> SecondTraits; 92 typedef VectorTraits<Second> SecondTraits;
93 93
94 static const bool needsDestruction = FirstTraits::needsDestruction || Second Traits::needsDestruction; 94 static const bool needsDestruction = FirstTraits::needsDestruction || Second Traits::needsDestruction;
95 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMe mset && SecondTraits::canInitializeWithMemset; 95 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMe mset && SecondTraits::canInitializeWithMemset;
96 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && Seco ndTraits::canMoveWithMemcpy; 96 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && Seco ndTraits::canMoveWithMemcpy;
97 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && Seco ndTraits::canCopyWithMemcpy; 97 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && Seco ndTraits::canCopyWithMemcpy;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \ 144 struct VectorTraits<ClassName> : VectorTraitsBase<ClassName> \
145 { \ 145 { \
146 static const bool canClearUnusedSlotsWithMemset = true; \ 146 static const bool canClearUnusedSlotsWithMemset = true; \
147 }; \ 147 }; \
148 } 148 }
149 149
150 using WTF::VectorTraits; 150 using WTF::VectorTraits;
151 using WTF::SimpleClassVectorTraits; 151 using WTF::SimpleClassVectorTraits;
152 152
153 #endif // WTF_VectorTraits_h 153 #endif // WTF_VectorTraits_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/VectorTest.cpp ('k') | third_party/WebKit/Source/wtf/WTFThreadData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698