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
3 // found in the LICENSE file.
5 #include "base/memory/ref_counted_memory.h"
7 #include "base/logging.h"
11 bool RefCountedMemory::Equals(
12 const scoped_refptr
<RefCountedMemory
>& other
) const {
14 size() == other
->size() &&
15 (memcmp(front(), other
->front(), size()) == 0);
18 RefCountedMemory::RefCountedMemory() {}
20 RefCountedMemory::~RefCountedMemory() {}
22 const unsigned char* RefCountedStaticMemory::front() const {
26 size_t RefCountedStaticMemory::size() const {
30 RefCountedStaticMemory::~RefCountedStaticMemory() {}
32 RefCountedBytes::RefCountedBytes() {}
34 RefCountedBytes::RefCountedBytes(const std::vector
<unsigned char>& initializer
)
35 : data_(initializer
) {
38 RefCountedBytes
* RefCountedBytes::TakeVector(
39 std::vector
<unsigned char>* to_destroy
) {
40 RefCountedBytes
* bytes
= new RefCountedBytes
;
41 bytes
->data_
.swap(*to_destroy
);
45 const unsigned char* RefCountedBytes::front() const {
46 // STL will assert if we do front() on an empty vector, but calling code
48 return size() ? &data_
.front() : NULL
;
51 size_t RefCountedBytes::size() const {
55 RefCountedBytes::~RefCountedBytes() {}
57 RefCountedString::RefCountedString() {}
59 RefCountedString::~RefCountedString() {}
62 RefCountedString
* RefCountedString::TakeString(std::string
* to_destroy
) {
63 RefCountedString
* self
= new RefCountedString
;
64 to_destroy
->swap(self
->data_
);
68 const unsigned char* RefCountedString::front() const {
69 return data_
.empty() ? NULL
:
70 reinterpret_cast<const unsigned char*>(data_
.data());
73 size_t RefCountedString::size() const {