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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLSrcsetParser.cpp

Issue 2617783002: Migrate WTF::Vector::append() to ::push_back() [part 12 of N] (Closed)
Patch Set: rebase 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) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. 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 are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return static_cast<float>(result.toDouble()); 100 return static_cast<float>(result.toDouble());
101 } 101 }
102 }; 102 };
103 103
104 template <typename CharType> 104 template <typename CharType>
105 static void appendDescriptorAndReset(const CharType* attributeStart, 105 static void appendDescriptorAndReset(const CharType* attributeStart,
106 const CharType*& descriptorStart, 106 const CharType*& descriptorStart,
107 const CharType* position, 107 const CharType* position,
108 Vector<DescriptorToken>& descriptors) { 108 Vector<DescriptorToken>& descriptors) {
109 if (position > descriptorStart) 109 if (position > descriptorStart)
110 descriptors.append(DescriptorToken(descriptorStart - attributeStart, 110 descriptors.push_back(DescriptorToken(descriptorStart - attributeStart,
111 position - descriptorStart)); 111 position - descriptorStart));
112 descriptorStart = 0; 112 descriptorStart = 0;
113 } 113 }
114 114
115 // The following is called appendCharacter to match the spec's terminology. 115 // The following is called appendCharacter to match the spec's terminology.
116 template <typename CharType> 116 template <typename CharType>
117 static void appendCharacter(const CharType* descriptorStart, 117 static void appendCharacter(const CharType* descriptorStart,
118 const CharType* position) { 118 const CharType* position) {
119 // Since we don't copy the tokens, this just set the point where the 119 // Since we don't copy the tokens, this just set the point where the
120 // descriptor tokens start. 120 // descriptor tokens start.
121 if (!descriptorStart) 121 if (!descriptorStart)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 String(imageURLStart, imageURLEnd - imageURLStart)))); 330 String(imageURLStart, imageURLEnd - imageURLStart))));
331 } 331 }
332 continue; 332 continue;
333 } 333 }
334 } 334 }
335 335
336 ASSERT(imageURLEnd > attributeStart); 336 ASSERT(imageURLEnd > attributeStart);
337 unsigned imageURLStartingPosition = imageURLStart - attributeStart; 337 unsigned imageURLStartingPosition = imageURLStart - attributeStart;
338 ASSERT(imageURLEnd > imageURLStart); 338 ASSERT(imageURLEnd > imageURLStart);
339 unsigned imageURLLength = imageURLEnd - imageURLStart; 339 unsigned imageURLLength = imageURLEnd - imageURLStart;
340 imageCandidates.append(ImageCandidate(attribute, imageURLStartingPosition, 340 imageCandidates.push_back(
341 imageURLLength, result, 341 ImageCandidate(attribute, imageURLStartingPosition, imageURLLength,
342 ImageCandidate::SrcsetOrigin)); 342 result, ImageCandidate::SrcsetOrigin));
343 // 11. Return to the step labeled splitting loop. 343 // 11. Return to the step labeled splitting loop.
344 } 344 }
345 } 345 }
346 346
347 static void parseImageCandidatesFromSrcsetAttribute( 347 static void parseImageCandidatesFromSrcsetAttribute(
348 const String& attribute, 348 const String& attribute,
349 Vector<ImageCandidate>& imageCandidates, 349 Vector<ImageCandidate>& imageCandidates,
350 Document* document) { 350 Document* document) {
351 if (attribute.isNull()) 351 if (attribute.isNull())
352 return; 352 return;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 } 423 }
424 424
425 std::stable_sort(imageCandidates.begin(), imageCandidates.end(), 425 std::stable_sort(imageCandidates.begin(), imageCandidates.end(),
426 compareByDensity); 426 compareByDensity);
427 427
428 Vector<ImageCandidate*> deDupedImageCandidates; 428 Vector<ImageCandidate*> deDupedImageCandidates;
429 float prevDensity = -1.0; 429 float prevDensity = -1.0;
430 for (ImageCandidate& image : imageCandidates) { 430 for (ImageCandidate& image : imageCandidates) {
431 if (image.density() != prevDensity && (!ignoreSrc || !image.srcOrigin())) 431 if (image.density() != prevDensity && (!ignoreSrc || !image.srcOrigin()))
432 deDupedImageCandidates.append(&image); 432 deDupedImageCandidates.push_back(&image);
433 prevDensity = image.density(); 433 prevDensity = image.density();
434 } 434 }
435 unsigned winner = selectionLogic(deDupedImageCandidates, deviceScaleFactor); 435 unsigned winner = selectionLogic(deDupedImageCandidates, deviceScaleFactor);
436 ASSERT(winner < deDupedImageCandidates.size()); 436 ASSERT(winner < deDupedImageCandidates.size());
437 winner = avoidDownloadIfHigherDensityResourceIsInCache(deDupedImageCandidates, 437 winner = avoidDownloadIfHigherDensityResourceIsInCache(deDupedImageCandidates,
438 winner, document); 438 winner, document);
439 439
440 float winningDensity = deDupedImageCandidates[winner]->density(); 440 float winningDensity = deDupedImageCandidates[winner]->density();
441 // 16. If an entry b in candidates has the same associated ... pixel density 441 // 16. If an entry b in candidates has the same associated ... pixel density
442 // as an earlier entry a in candidates, 442 // as an earlier entry a in candidates,
(...skipping 29 matching lines...) Expand all
472 return ImageCandidate(srcAttribute, 0, srcAttribute.length(), 472 return ImageCandidate(srcAttribute, 0, srcAttribute.length(),
473 DescriptorParsingResult(), ImageCandidate::SrcOrigin); 473 DescriptorParsingResult(), ImageCandidate::SrcOrigin);
474 } 474 }
475 475
476 Vector<ImageCandidate> imageCandidates; 476 Vector<ImageCandidate> imageCandidates;
477 477
478 parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates, 478 parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates,
479 document); 479 document);
480 480
481 if (!srcAttribute.isEmpty()) 481 if (!srcAttribute.isEmpty())
482 imageCandidates.append( 482 imageCandidates.push_back(
483 ImageCandidate(srcAttribute, 0, srcAttribute.length(), 483 ImageCandidate(srcAttribute, 0, srcAttribute.length(),
484 DescriptorParsingResult(), ImageCandidate::SrcOrigin)); 484 DescriptorParsingResult(), ImageCandidate::SrcOrigin));
485 485
486 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates, 486 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates,
487 document); 487 document);
488 } 488 }
489 489
490 String bestFitSourceForImageAttributes(float deviceScaleFactor, 490 String bestFitSourceForImageAttributes(float deviceScaleFactor,
491 float sourceSize, 491 float sourceSize,
492 const String& srcAttribute, 492 const String& srcAttribute,
493 ImageCandidate& srcsetImageCandidate) { 493 ImageCandidate& srcsetImageCandidate) {
494 if (srcsetImageCandidate.isEmpty()) 494 if (srcsetImageCandidate.isEmpty())
495 return srcAttribute; 495 return srcAttribute;
496 496
497 Vector<ImageCandidate> imageCandidates; 497 Vector<ImageCandidate> imageCandidates;
498 imageCandidates.append(srcsetImageCandidate); 498 imageCandidates.push_back(srcsetImageCandidate);
499 499
500 if (!srcAttribute.isEmpty()) 500 if (!srcAttribute.isEmpty())
501 imageCandidates.append( 501 imageCandidates.push_back(
502 ImageCandidate(srcAttribute, 0, srcAttribute.length(), 502 ImageCandidate(srcAttribute, 0, srcAttribute.length(),
503 DescriptorParsingResult(), ImageCandidate::SrcOrigin)); 503 DescriptorParsingResult(), ImageCandidate::SrcOrigin));
504 504
505 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates) 505 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates)
506 .toString(); 506 .toString();
507 } 507 }
508 508
509 } // namespace blink 509 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698