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