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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/ScriptRunIterator.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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ScriptRunIterator.h" 5 #include "ScriptRunIterator.h"
6 6
7 #include "platform/text/ICUError.h" 7 #include "platform/text/ICUError.h"
8 #include "wtf/Threading.h" 8 #include "wtf/Threading.h"
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return; 52 return;
53 } 53 }
54 54
55 if (primaryScript != USCRIPT_INHERITED && primaryScript != USCRIPT_COMMON && 55 if (primaryScript != USCRIPT_INHERITED && primaryScript != USCRIPT_COMMON &&
56 primaryScript != USCRIPT_INVALID_CODE) { 56 primaryScript != USCRIPT_INVALID_CODE) {
57 // Not common or primary, with extensions that are not in order. We know 57 // Not common or primary, with extensions that are not in order. We know
58 // the primary, so we insert it at the front and swap the previous front 58 // the primary, so we insert it at the front and swap the previous front
59 // to somewhere else in the list. 59 // to somewhere else in the list.
60 auto it = std::find(dst.begin() + 1, dst.end(), primaryScript); 60 auto it = std::find(dst.begin() + 1, dst.end(), primaryScript);
61 if (it == dst.end()) { 61 if (it == dst.end()) {
62 dst.append(primaryScript); 62 dst.push_back(primaryScript);
63 } 63 }
64 std::swap(*dst.begin(), *it); 64 std::swap(*dst.begin(), *it);
65 return; 65 return;
66 } 66 }
67 67
68 if (primaryScript == USCRIPT_COMMON) { 68 if (primaryScript == USCRIPT_COMMON) {
69 if (count == 1) { 69 if (count == 1) {
70 // Common with a preferred script. Keep common at head. 70 // Common with a preferred script. Keep common at head.
71 dst.prepend(primaryScript); 71 dst.prepend(primaryScript);
72 return; 72 return;
73 } 73 }
74 74
75 // Ignore common. Find the preferred script of the multiple scripts that 75 // Ignore common. Find the preferred script of the multiple scripts that
76 // remain, and ensure it is at the head. Just keep swapping them in, 76 // remain, and ensure it is at the head. Just keep swapping them in,
77 // there aren't likely to be many. 77 // there aren't likely to be many.
78 for (size_t i = 1; i < dst.size(); ++i) { 78 for (size_t i = 1; i < dst.size(); ++i) {
79 if (dst.at(0) == USCRIPT_LATIN || dst.at(i) < dst.at(0)) { 79 if (dst.at(0) == USCRIPT_LATIN || dst.at(i) < dst.at(0)) {
80 std::swap(dst.at(0), dst.at(i)); 80 std::swap(dst.at(0), dst.at(i));
81 } 81 }
82 } 82 }
83 return; 83 return;
84 } 84 }
85 85
86 // The primary is inherited, and there are other scripts. Put inherited at 86 // The primary is inherited, and there are other scripts. Put inherited at
87 // the front, the true primary next, and then the others in random order. 87 // the front, the true primary next, and then the others in random order.
88 // TODO: Take into account the language of a document if available. 88 // TODO: Take into account the language of a document if available.
89 // Otherwise, use Unicode block as a tie breaker. Comparing 89 // Otherwise, use Unicode block as a tie breaker. Comparing
90 // ScriptCodes as integers is not meaningful because 'old' scripts are 90 // ScriptCodes as integers is not meaningful because 'old' scripts are
91 // just sorted in alphabetic order. 91 // just sorted in alphabetic order.
92 dst.append(dst.at(0)); 92 dst.push_back(dst.at(0));
93 dst.at(0) = primaryScript; 93 dst.at(0) = primaryScript;
94 for (size_t i = 2; i < dst.size(); ++i) { 94 for (size_t i = 2; i < dst.size(); ++i) {
95 if (dst.at(1) == USCRIPT_LATIN || dst.at(i) < dst.at(1)) { 95 if (dst.at(1) == USCRIPT_LATIN || dst.at(i) < dst.at(1)) {
96 std::swap(dst.at(1), dst.at(i)); 96 std::swap(dst.at(1), dst.at(i));
97 } 97 }
98 } 98 }
99 } 99 }
100 100
101 UChar32 ICUScriptData::getPairedBracket(UChar32 ch) const { 101 UChar32 ICUScriptData::getPairedBracket(UChar32 ch) const {
102 return u_getBidiPairedBracket(ch); 102 return u_getBidiPairedBracket(ch);
(...skipping 22 matching lines...) Expand all
125 m_commonPreferred(USCRIPT_COMMON), 125 m_commonPreferred(USCRIPT_COMMON),
126 m_scriptData(data) { 126 m_scriptData(data) {
127 ASSERT(text); 127 ASSERT(text);
128 ASSERT(data); 128 ASSERT(data);
129 129
130 if (m_aheadPos < m_length) { 130 if (m_aheadPos < m_length) {
131 m_currentSet.clear(); 131 m_currentSet.clear();
132 // Priming the m_currentSet with USCRIPT_COMMON here so that the first 132 // Priming the m_currentSet with USCRIPT_COMMON here so that the first
133 // resolution between m_currentSet and m_nextSet in mergeSets() leads to 133 // resolution between m_currentSet and m_nextSet in mergeSets() leads to
134 // chosing the script of the first consumed character. 134 // chosing the script of the first consumed character.
135 m_currentSet.append(USCRIPT_COMMON); 135 m_currentSet.push_back(USCRIPT_COMMON);
136 U16_NEXT(m_text, m_aheadPos, m_length, m_aheadCharacter); 136 U16_NEXT(m_text, m_aheadPos, m_length, m_aheadCharacter);
137 m_scriptData->getScripts(m_aheadCharacter, m_aheadSet); 137 m_scriptData->getScripts(m_aheadCharacter, m_aheadSet);
138 } 138 }
139 } 139 }
140 140
141 ScriptRunIterator::ScriptRunIterator(const UChar* text, size_t length) 141 ScriptRunIterator::ScriptRunIterator(const UChar* text, size_t length)
142 : ScriptRunIterator(text, length, ICUScriptData::instance()) {} 142 : ScriptRunIterator(text, length, ICUScriptData::instance()) {}
143 143
144 bool ScriptRunIterator::consume(unsigned& limit, UScriptCode& script) { 144 bool ScriptRunIterator::consume(unsigned& limit, UScriptCode& script) {
145 if (m_currentSet.isEmpty()) { 145 if (m_currentSet.isEmpty()) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 void ScriptRunIterator::closeBracket(UChar32 ch) { 189 void ScriptRunIterator::closeBracket(UChar32 ch) {
190 if (m_brackets.size() > 0) { 190 if (m_brackets.size() > 0) {
191 UChar32 target = m_scriptData->getPairedBracket(ch); 191 UChar32 target = m_scriptData->getPairedBracket(ch);
192 for (auto it = m_brackets.rbegin(); it != m_brackets.rend(); ++it) { 192 for (auto it = m_brackets.rbegin(); it != m_brackets.rend(); ++it) {
193 if (it->ch == target) { 193 if (it->ch == target) {
194 // Have a match, use open paren's resolved script. 194 // Have a match, use open paren's resolved script.
195 UScriptCode script = it->script; 195 UScriptCode script = it->script;
196 m_nextSet.clear(); 196 m_nextSet.clear();
197 m_nextSet.append(script); 197 m_nextSet.push_back(script);
198 198
199 // And pop stack to this point. 199 // And pop stack to this point.
200 int numPopped = std::distance(m_brackets.rbegin(), it); 200 int numPopped = std::distance(m_brackets.rbegin(), it);
201 // TODO: No resize operation in WTF::Deque? 201 // TODO: No resize operation in WTF::Deque?
202 for (int i = 0; i < numPopped; ++i) 202 for (int i = 0; i < numPopped; ++i)
203 m_brackets.removeLast(); 203 m_brackets.removeLast();
204 m_bracketsFixupDepth = 204 m_bracketsFixupDepth =
205 std::max(static_cast<size_t>(0), m_bracketsFixupDepth - numPopped); 205 std::max(static_cast<size_t>(0), m_bracketsFixupDepth - numPopped);
206 return; 206 return;
207 } 207 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 355 }
356 return true; 356 return true;
357 } 357 }
358 358
359 UScriptCode ScriptRunIterator::resolveCurrentScript() const { 359 UScriptCode ScriptRunIterator::resolveCurrentScript() const {
360 UScriptCode result = m_currentSet.at(0); 360 UScriptCode result = m_currentSet.at(0);
361 return result == USCRIPT_COMMON ? m_commonPreferred : result; 361 return result == USCRIPT_COMMON ? m_commonPreferred : result;
362 } 362 }
363 363
364 } // namespace blink 364 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698