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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp

Issue 2776203002: Migrate WTF::Vector::remove() to ::erase() (Closed)
Patch Set: rebase, repatch VectorTest Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "modules/fetch/FetchHeaderList.h" 5 #include "modules/fetch/FetchHeaderList.h"
6 6
7 #include "platform/loader/fetch/FetchUtils.h" 7 #include "platform/loader/fetch/FetchUtils.h"
8 #include "platform/network/HTTPParsers.h" 8 #include "platform/network/HTTPParsers.h"
9 #include "wtf/PtrUtil.h" 9 #include "wtf/PtrUtil.h"
10 #include <algorithm> 10 #include <algorithm>
(...skipping 29 matching lines...) Expand all
40 // 2. If there are any headers in |list| whose name is |name|, set the value 40 // 2. If there are any headers in |list| whose name is |name|, set the value
41 // of the first such header to |value| and remove the others. 41 // of the first such header to |value| and remove the others.
42 // 3. Otherwise, append a new header whose name is |name| and value is 42 // 3. Otherwise, append a new header whose name is |name| and value is
43 // |value|, to |list|." 43 // |value|, to |list|."
44 const String lowercasedName = name.lower(); 44 const String lowercasedName = name.lower();
45 for (size_t i = 0; i < m_headerList.size(); ++i) { 45 for (size_t i = 0; i < m_headerList.size(); ++i) {
46 if (m_headerList[i]->first == lowercasedName) { 46 if (m_headerList[i]->first == lowercasedName) {
47 m_headerList[i]->second = value; 47 m_headerList[i]->second = value;
48 for (size_t j = i + 1; j < m_headerList.size();) { 48 for (size_t j = i + 1; j < m_headerList.size();) {
49 if (m_headerList[j]->first == lowercasedName) 49 if (m_headerList[j]->first == lowercasedName)
50 m_headerList.remove(j); 50 m_headerList.erase(j);
51 else 51 else
52 ++j; 52 ++j;
53 } 53 }
54 return; 54 return;
55 } 55 }
56 } 56 }
57 m_headerList.push_back(WTF::makeUnique<Header>(lowercasedName, value)); 57 m_headerList.push_back(WTF::makeUnique<Header>(lowercasedName, value));
58 } 58 }
59 59
60 String FetchHeaderList::extractMIMEType() const { 60 String FetchHeaderList::extractMIMEType() const {
(...skipping 11 matching lines...) Expand all
72 size_t FetchHeaderList::size() const { 72 size_t FetchHeaderList::size() const {
73 return m_headerList.size(); 73 return m_headerList.size();
74 } 74 }
75 75
76 void FetchHeaderList::remove(const String& name) { 76 void FetchHeaderList::remove(const String& name) {
77 // "To delete a name (|name|) from a header list (|list|), remove all headers 77 // "To delete a name (|name|) from a header list (|list|), remove all headers
78 // whose name is |name|, byte lowercased, from |list|." 78 // whose name is |name|, byte lowercased, from |list|."
79 const String lowercasedName = name.lower(); 79 const String lowercasedName = name.lower();
80 for (size_t i = 0; i < m_headerList.size();) { 80 for (size_t i = 0; i < m_headerList.size();) {
81 if (m_headerList[i]->first == lowercasedName) 81 if (m_headerList[i]->first == lowercasedName)
82 m_headerList.remove(i); 82 m_headerList.erase(i);
83 else 83 else
84 ++i; 84 ++i;
85 } 85 }
86 } 86 }
87 87
88 bool FetchHeaderList::get(const String& name, String& result) const { 88 bool FetchHeaderList::get(const String& name, String& result) const {
89 const String lowercasedName = name.lower(); 89 const String lowercasedName = name.lower();
90 bool found = false; 90 bool found = false;
91 for (const auto& header : m_headerList) { 91 for (const auto& header : m_headerList) {
92 if (header->first == lowercasedName) { 92 if (header->first == lowercasedName) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 std::sort( 143 std::sort(
144 m_headerList.begin(), m_headerList.end(), 144 m_headerList.begin(), m_headerList.end(),
145 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) { 145 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) {
146 return WTF::codePointCompareLessThan(a->first, b->first); 146 return WTF::codePointCompareLessThan(a->first, b->first);
147 }); 147 });
148 148
149 for (size_t index = m_headerList.size() - 1; index > 0; --index) { 149 for (size_t index = m_headerList.size() - 1; index > 0; --index) {
150 if (m_headerList[index - 1]->first == m_headerList[index]->first) { 150 if (m_headerList[index - 1]->first == m_headerList[index]->first) {
151 m_headerList[index - 1]->second.append(","); 151 m_headerList[index - 1]->second.append(",");
152 m_headerList[index - 1]->second.append(m_headerList[index]->second); 152 m_headerList[index - 1]->second.append(m_headerList[index]->second);
153 m_headerList.remove(index, 1); 153 m_headerList.erase(index, 1);
154 } 154 }
155 } 155 }
156 } 156 }
157 157
158 bool FetchHeaderList::isValidHeaderName(const String& name) { 158 bool FetchHeaderList::isValidHeaderName(const String& name) {
159 // "A name is a case-insensitive byte sequence that matches the field-name 159 // "A name is a case-insensitive byte sequence that matches the field-name
160 // token production." 160 // token production."
161 return isValidHTTPToken(name); 161 return isValidHTTPToken(name);
162 } 162 }
163 163
164 bool FetchHeaderList::isValidHeaderValue(const String& value) { 164 bool FetchHeaderList::isValidHeaderValue(const String& value) {
165 // "A value is a byte sequence that matches the field-value token production 165 // "A value is a byte sequence that matches the field-value token production
166 // and contains no 0x0A or 0x0D bytes." 166 // and contains no 0x0A or 0x0D bytes."
167 return isValidHTTPHeaderValue(value); 167 return isValidHTTPHeaderValue(value);
168 } 168 }
169 169
170 } // namespace blink 170 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698