| OLD | NEW | 
|---|
| 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 "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" | 
| 9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" | 
| 10 #include "wtf/PtrUtil.h" | 10 #include "wtf/PtrUtil.h" | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 49 | 49 | 
| 50   T* access() { | 50   T* access() { | 
| 51     if (m_data && !m_ownCopy) { | 51     if (m_data && !m_ownCopy) { | 
| 52       *m_data = (*m_data)->copy(); | 52       *m_data = (*m_data)->copy(); | 
| 53       m_ownCopy = true; | 53       m_ownCopy = true; | 
| 54     } | 54     } | 
| 55     return m_data ? m_data->get() : nullptr; | 55     return m_data ? m_data->get() : nullptr; | 
| 56   } | 56   } | 
| 57 | 57 | 
| 58   void init() { | 58   void init() { | 
| 59     ASSERT(!m_data); | 59     DCHECK(!m_data); | 
| 60     m_data = WTF::wrapUnique(new Persistent<T>(T::create())); | 60     m_data = WTF::wrapUnique(new Persistent<T>(T::create())); | 
| 61     m_ownCopy = true; | 61     m_ownCopy = true; | 
| 62   } | 62   } | 
| 63 | 63 | 
| 64   bool operator==(const DataPersistent<T>& o) const { | 64   bool operator==(const DataPersistent<T>& o) const { | 
| 65     ASSERT(m_data); | 65     DCHECK(m_data); | 
| 66     ASSERT(o.m_data); | 66     DCHECK(o.m_data); | 
| 67     return m_data->get() == o.m_data->get() || | 67     return m_data->get() == o.m_data->get() || | 
| 68            *m_data->get() == *o.m_data->get(); | 68            *m_data->get() == *o.m_data->get(); | 
| 69   } | 69   } | 
| 70 | 70 | 
| 71   bool operator!=(const DataPersistent<T>& o) const { | 71   bool operator!=(const DataPersistent<T>& o) const { | 
| 72     ASSERT(m_data); | 72     DCHECK(m_data); | 
| 73     ASSERT(o.m_data); | 73     DCHECK(o.m_data); | 
| 74     return m_data->get() != o.m_data->get() && | 74     return m_data->get() != o.m_data->get() && | 
| 75            *m_data->get() != *o.m_data->get(); | 75            *m_data->get() != *o.m_data->get(); | 
| 76   } | 76   } | 
| 77 | 77 | 
| 78   void operator=(std::nullptr_t) { m_data.clear(); } | 78   void operator=(std::nullptr_t) { m_data.clear(); } | 
| 79 | 79 | 
| 80  private: | 80  private: | 
| 81   // Reduce size of DataPersistent<> by delaying creation of Persistent<>. | 81   // Reduce size of DataPersistent<> by delaying creation of Persistent<>. | 
| 82   std::unique_ptr<Persistent<T>> m_data; | 82   std::unique_ptr<Persistent<T>> m_data; | 
| 83   unsigned m_ownCopy : 1; | 83   unsigned m_ownCopy : 1; | 
| 84 }; | 84 }; | 
| 85 | 85 | 
| 86 }  // namespace blink | 86 }  // namespace blink | 
| 87 | 87 | 
| 88 #endif  // DataPersistent_h | 88 #endif  // DataPersistent_h | 
| OLD | NEW | 
|---|