| 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> | |
| 8 | |
| 9 #include "base/logging.h" | 7 #include "base/logging.h" |
| 10 | 8 |
| 11 namespace base { | 9 namespace base { |
| 12 | 10 |
| 13 bool RefCountedMemory::Equals( | 11 bool RefCountedMemory::Equals( |
| 14 const scoped_refptr<RefCountedMemory>& other) const { | 12 const scoped_refptr<RefCountedMemory>& other) const { |
| 15 return other.get() && | 13 return other.get() && |
| 16 size() == other->size() && | 14 size() == other->size() && |
| 17 (memcmp(front(), other->front(), size()) == 0); | 15 (memcmp(front(), other->front(), size()) == 0); |
| 18 } | 16 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 70 |
| 73 const unsigned char* RefCountedString::front() const { | 71 const unsigned char* RefCountedString::front() const { |
| 74 return data_.empty() ? NULL : | 72 return data_.empty() ? NULL : |
| 75 reinterpret_cast<const unsigned char*>(data_.data()); | 73 reinterpret_cast<const unsigned char*>(data_.data()); |
| 76 } | 74 } |
| 77 | 75 |
| 78 size_t RefCountedString::size() const { | 76 size_t RefCountedString::size() const { |
| 79 return data_.size(); | 77 return data_.size(); |
| 80 } | 78 } |
| 81 | 79 |
| 82 RefCountedMallocedMemory::RefCountedMallocedMemory( | |
| 83 void* data, size_t length) | |
| 84 : data_(reinterpret_cast<unsigned char*>(data)), length_(length) { | |
| 85 DCHECK(data || length == 0); | |
| 86 } | |
| 87 | |
| 88 const unsigned char* RefCountedMallocedMemory::front() const { | |
| 89 return length_ ? data_ : NULL; | |
| 90 } | |
| 91 | |
| 92 size_t RefCountedMallocedMemory::size() const { | |
| 93 return length_; | |
| 94 } | |
| 95 | |
| 96 RefCountedMallocedMemory::~RefCountedMallocedMemory() { | |
| 97 free(data_); | |
| 98 } | |
| 99 | |
| 100 } // namespace base | 80 } // namespace base |
| OLD | NEW |