OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/memory/ref_counted_memory.h" | 5 #include "base/memory/ref_counted_memory.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 bool RefCountedMemory::Equals( | 13 bool RefCountedMemory::Equals( |
14 const scoped_refptr<RefCountedMemory>& other) const { | 14 const scoped_refptr<RefCountedMemory>& other) const { |
15 return other.get() && | 15 return other.get() && |
16 size() == other->size() && | 16 size() == other->size() && |
17 (memcmp(front(), other->front(), size()) == 0); | 17 (memcmp(front(), other->front(), size()) == 0); |
18 } | 18 } |
19 | 19 |
20 RefCountedMemory::RefCountedMemory() {} | 20 RefCountedMemory::RefCountedMemory() {} |
21 | 21 |
22 RefCountedMemory::~RefCountedMemory() {} | 22 RefCountedMemory::~RefCountedMemory() {} |
23 | 23 |
| 24 base::StringPiece RefCountedMemory::AsString(const RefCountedMemory* memory) { |
| 25 if (memory) { |
| 26 return base::StringPiece(reinterpret_cast<const char*>(memory->front()), |
| 27 memory->size()); |
| 28 } else { |
| 29 return base::StringPiece(); |
| 30 } |
| 31 } |
| 32 |
24 const unsigned char* RefCountedStaticMemory::front() const { | 33 const unsigned char* RefCountedStaticMemory::front() const { |
25 return data_; | 34 return data_; |
26 } | 35 } |
27 | 36 |
28 size_t RefCountedStaticMemory::size() const { | 37 size_t RefCountedStaticMemory::size() const { |
29 return length_; | 38 return length_; |
30 } | 39 } |
31 | 40 |
32 RefCountedStaticMemory::~RefCountedStaticMemory() {} | 41 RefCountedStaticMemory::~RefCountedStaticMemory() {} |
33 | 42 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 97 |
89 size_t RefCountedMallocedMemory::size() const { | 98 size_t RefCountedMallocedMemory::size() const { |
90 return length_; | 99 return length_; |
91 } | 100 } |
92 | 101 |
93 RefCountedMallocedMemory::~RefCountedMallocedMemory() { | 102 RefCountedMallocedMemory::~RefCountedMallocedMemory() { |
94 free(data_); | 103 free(data_); |
95 } | 104 } |
96 | 105 |
97 } // namespace base | 106 } // namespace base |
OLD | NEW |