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

Side by Side Diff: Source/wtf/RawPtr.h

Issue 209433004: Do not zero-initialize RawPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« 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 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 30 matching lines...) Expand all
41 // use reference counting or garbage collection based on a 41 // use reference counting or garbage collection based on a
42 // compile-time flag. 42 // compile-time flag.
43 43
44 namespace WTF { 44 namespace WTF {
45 45
46 template<typename T> 46 template<typename T>
47 class RawPtr { 47 class RawPtr {
48 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(RawPtr); 48 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(RawPtr);
49 WTF_DISALLOW_ZERO_ASSIGNMENT(RawPtr); 49 WTF_DISALLOW_ZERO_ASSIGNMENT(RawPtr);
50 public: 50 public:
51 RawPtr() : m_ptr(0) { } 51 RawPtr()
52 {
53 #ifndef NDEBUG
54 m_ptr = reinterpret_cast<T*>(rawPtrZapValue);
55 #endif
56 }
52 RawPtr(std::nullptr_t) : m_ptr(0) { } 57 RawPtr(std::nullptr_t) : m_ptr(0) { }
53 RawPtr(T* ptr) : m_ptr(ptr) { } 58 RawPtr(T* ptr) : m_ptr(ptr) { }
54 explicit RawPtr(T& reference) : m_ptr(&reference) { } 59 explicit RawPtr(T& reference) : m_ptr(&reference) { }
55 RawPtr(const RawPtr& other) 60 RawPtr(const RawPtr& other)
56 : m_ptr(other.get()) 61 : m_ptr(other.get())
57 { 62 {
58 } 63 }
59 64
60 template<typename U> 65 template<typename U>
61 RawPtr(const RawPtr<U>& other) 66 RawPtr(const RawPtr<U>& other)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 bool operator!() const { return !m_ptr; } 114 bool operator!() const { return !m_ptr; }
110 115
111 void swap(RawPtr& o) 116 void swap(RawPtr& o)
112 { 117 {
113 std::swap(m_ptr, o.m_ptr); 118 std::swap(m_ptr, o.m_ptr);
114 } 119 }
115 120
116 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } 121 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
117 122
118 private: 123 private:
124 static const uintptr_t rawPtrZapValue = 0x3a3a3a3a;
tkent 2014/03/24 09:27:06 nit: I prefer an odd number.
119 T* m_ptr; 125 T* m_ptr;
120 }; 126 };
121 127
122 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP tr<U>& p) 128 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP tr<U>& p)
123 { 129 {
124 return RawPtr<T>(static_cast<T*>(p.get())); 130 return RawPtr<T>(static_cast<T*>(p.get()));
125 } 131 }
126 132
127 template<typename T> inline T* getPtr(const RawPtr<T>& p) 133 template<typename T> inline T* getPtr(const RawPtr<T>& p)
128 { 134 {
129 return p.get(); 135 return p.get();
130 } 136 }
131 137
132 } // namespace WTF 138 } // namespace WTF
133 139
134 using WTF::RawPtr; 140 using WTF::RawPtr;
135 141
136 #endif 142 #endif
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