Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: base/memory/ref_counted_memory.cc

Issue 78603002: Added RefCountedMallocedMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: grammar fix Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/memory/ref_counted_memory.h ('k') | base/memory/ref_counted_memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/memory/ref_counted_memory.h ('k') | base/memory/ref_counted_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698