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

Side by Side Diff: third_party/WebKit/Source/platform/blob/BlobData.cpp

Issue 2502413004: WTF/std normalization: replace WTF::Vector::last with ::back (Closed)
Patch Set: rebase Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 134
135 void BlobData::appendText(const String& text, 135 void BlobData::appendText(const String& text,
136 bool doNormalizeLineEndingsToNative) { 136 bool doNormalizeLineEndingsToNative) {
137 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 137 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
138 << "Blobs with a unknown-size file cannot have other items."; 138 << "Blobs with a unknown-size file cannot have other items.";
139 CString utf8Text = UTF8Encoding().encode(text, WTF::EntitiesForUnencodables); 139 CString utf8Text = UTF8Encoding().encode(text, WTF::EntitiesForUnencodables);
140 RefPtr<RawData> data = nullptr; 140 RefPtr<RawData> data = nullptr;
141 Vector<char>* buffer; 141 Vector<char>* buffer;
142 if (canConsolidateData(text.length())) { 142 if (canConsolidateData(text.length())) {
143 buffer = m_items.last().data->mutableData(); 143 buffer = m_items.back().data->mutableData();
144 } else { 144 } else {
145 data = RawData::create(); 145 data = RawData::create();
146 buffer = data->mutableData(); 146 buffer = data->mutableData();
147 } 147 }
148 148
149 if (doNormalizeLineEndingsToNative) { 149 if (doNormalizeLineEndingsToNative) {
150 normalizeLineEndingsToNative(utf8Text, *buffer); 150 normalizeLineEndingsToNative(utf8Text, *buffer);
151 } else { 151 } else {
152 buffer->append(utf8Text.data(), utf8Text.length()); 152 buffer->append(utf8Text.data(), utf8Text.length());
153 } 153 }
154 154
155 if (data) 155 if (data)
156 m_items.append(BlobDataItem(data.release())); 156 m_items.append(BlobDataItem(data.release()));
157 } 157 }
158 158
159 void BlobData::appendBytes(const void* bytes, size_t length) { 159 void BlobData::appendBytes(const void* bytes, size_t length) {
160 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 160 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
161 << "Blobs with a unknown-size file cannot have other items."; 161 << "Blobs with a unknown-size file cannot have other items.";
162 if (canConsolidateData(length)) { 162 if (canConsolidateData(length)) {
163 m_items.last().data->mutableData()->append(static_cast<const char*>(bytes), 163 m_items.back().data->mutableData()->append(static_cast<const char*>(bytes),
164 length); 164 length);
165 return; 165 return;
166 } 166 }
167 RefPtr<RawData> data = RawData::create(); 167 RefPtr<RawData> data = RawData::create();
168 Vector<char>* buffer = data->mutableData(); 168 Vector<char>* buffer = data->mutableData();
169 buffer->append(static_cast<const char*>(bytes), length); 169 buffer->append(static_cast<const char*>(bytes), length);
170 m_items.append(BlobDataItem(data.release())); 170 m_items.append(BlobDataItem(data.release()));
171 } 171 }
172 172
173 long long BlobData::length() const { 173 long long BlobData::length() const {
(...skipping 17 matching lines...) Expand all
191 case BlobDataItem::FileSystemURL: 191 case BlobDataItem::FileSystemURL:
192 return BlobDataItem::toEndOfFile; 192 return BlobDataItem::toEndOfFile;
193 } 193 }
194 } 194 }
195 return length; 195 return length;
196 } 196 }
197 197
198 bool BlobData::canConsolidateData(size_t length) { 198 bool BlobData::canConsolidateData(size_t length) {
199 if (m_items.isEmpty()) 199 if (m_items.isEmpty())
200 return false; 200 return false;
201 BlobDataItem& lastItem = m_items.last(); 201 BlobDataItem& lastItem = m_items.back();
202 if (lastItem.type != BlobDataItem::Data) 202 if (lastItem.type != BlobDataItem::Data)
203 return false; 203 return false;
204 if (lastItem.data->length() + length > kMaxConsolidatedItemSizeInBytes) 204 if (lastItem.data->length() + length > kMaxConsolidatedItemSizeInBytes)
205 return false; 205 return false;
206 return true; 206 return true;
207 } 207 }
208 208
209 BlobDataHandle::BlobDataHandle() 209 BlobDataHandle::BlobDataHandle()
210 : m_uuid(createCanonicalUUIDString()), m_size(0) { 210 : m_uuid(createCanonicalUUIDString()), m_size(0) {
211 BlobRegistry::registerBlobData(m_uuid, BlobData::create()); 211 BlobRegistry::registerBlobData(m_uuid, BlobData::create());
(...skipping 13 matching lines...) Expand all
225 m_type(isValidBlobType(type) ? type.isolatedCopy() : ""), 225 m_type(isValidBlobType(type) ? type.isolatedCopy() : ""),
226 m_size(size) { 226 m_size(size) {
227 BlobRegistry::addBlobDataRef(m_uuid); 227 BlobRegistry::addBlobDataRef(m_uuid);
228 } 228 }
229 229
230 BlobDataHandle::~BlobDataHandle() { 230 BlobDataHandle::~BlobDataHandle() {
231 BlobRegistry::removeBlobDataRef(m_uuid); 231 BlobRegistry::removeBlobDataRef(m_uuid);
232 } 232 }
233 233
234 } // namespace blink 234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/SharedBuffer.cpp ('k') | third_party/WebKit/Source/platform/fonts/GlyphBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698