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

Side by Side Diff: third_party/WebKit/Source/platform/SharedBuffer.cpp

Issue 2615813003: Migrate WTF::Vector::append() to ::push_back() [part 14 of N] (Closed)
Patch Set: rebase, small fix in FontSettings.h Created 3 years, 11 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 if (m_size <= kSegmentSize) { 101 if (m_size <= kSegmentSize) {
102 // No need to use segments for small resource data. 102 // No need to use segments for small resource data.
103 m_buffer.append(data, length); 103 m_buffer.append(data, length);
104 return; 104 return;
105 } 105 }
106 106
107 char* segment; 107 char* segment;
108 if (!positionInSegment) { 108 if (!positionInSegment) {
109 segment = allocateSegment(); 109 segment = allocateSegment();
110 m_segments.append(segment); 110 m_segments.push_back(segment);
111 } else 111 } else
112 segment = m_segments.back() + positionInSegment; 112 segment = m_segments.back() + positionInSegment;
113 113
114 size_t segmentFreeSpace = kSegmentSize - positionInSegment; 114 size_t segmentFreeSpace = kSegmentSize - positionInSegment;
115 size_t bytesToCopy = std::min(length, segmentFreeSpace); 115 size_t bytesToCopy = std::min(length, segmentFreeSpace);
116 116
117 for (;;) { 117 for (;;) {
118 memcpy(segment, data, bytesToCopy); 118 memcpy(segment, data, bytesToCopy);
119 if (length == bytesToCopy) 119 if (length == bytesToCopy)
120 break; 120 break;
121 121
122 length -= bytesToCopy; 122 length -= bytesToCopy;
123 data += bytesToCopy; 123 data += bytesToCopy;
124 segment = allocateSegment(); 124 segment = allocateSegment();
125 m_segments.append(segment); 125 m_segments.push_back(segment);
126 bytesToCopy = std::min(length, static_cast<size_t>(kSegmentSize)); 126 bytesToCopy = std::min(length, static_cast<size_t>(kSegmentSize));
127 } 127 }
128 } 128 }
129 129
130 void SharedBuffer::append(const Vector<char>& data) { 130 void SharedBuffer::append(const Vector<char>& data) {
131 append(data.data(), data.size()); 131 append(data.data(), data.size());
132 } 132 }
133 133
134 void SharedBuffer::clear() { 134 void SharedBuffer::clear() {
135 for (size_t i = 0; i < m_segments.size(); ++i) 135 for (size_t i = 0; i < m_segments.size(); ++i)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // using fastMalloc. 260 // using fastMalloc.
261 const String dataDumpName = dumpPrefix + "/segments"; 261 const String dataDumpName = dumpPrefix + "/segments";
262 auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName); 262 auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName);
263 dump->addScalar("size", "bytes", m_size); 263 dump->addScalar("size", "bytes", m_size);
264 memoryDump->addSuballocation( 264 memoryDump->addSuballocation(
265 dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); 265 dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
266 } 266 }
267 } 267 }
268 268
269 } // namespace blink 269 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698