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

Side by Side Diff: third_party/WebKit/Source/core/dom/SpaceSplitString.cpp

Issue 2903803002: DOMTokenList should unify duplicated tokens. (Closed)
Patch Set: Update a -expected.txt Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/frames/sandboxed-iframe-attribute-parsing-03-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 David Smith (catfish.man@gmail.com) 2 * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
3 * Copyright (C) 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA. 18 * Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21 #include "core/dom/SpaceSplitString.h" 21 #include "core/dom/SpaceSplitString.h"
22 22
23 #include "core/html/parser/HTMLParserIdioms.h" 23 #include "core/html/parser/HTMLParserIdioms.h"
24 #include "platform/wtf/ASCIICType.h" 24 #include "platform/wtf/ASCIICType.h"
25 #include "platform/wtf/HashMap.h" 25 #include "platform/wtf/HashMap.h"
26 #include "platform/wtf/HashSet.h"
26 #include "platform/wtf/text/AtomicStringHash.h" 27 #include "platform/wtf/text/AtomicStringHash.h"
27 28
28 namespace blink { 29 namespace blink {
29 30
30 template <typename CharacterType> 31 template <typename CharacterType>
31 static inline bool HasNonASCIIOrUpper(const CharacterType* characters, 32 static inline bool HasNonASCIIOrUpper(const CharacterType* characters,
32 unsigned length) { 33 unsigned length) {
33 bool has_upper = false; 34 bool has_upper = false;
34 CharacterType ored = 0; 35 CharacterType ored = 0;
35 for (unsigned i = 0; i < length; i++) { 36 for (unsigned i = 0; i < length; i++) {
36 CharacterType c = characters[i]; 37 CharacterType c = characters[i];
37 has_upper |= IsASCIIUpper(c); 38 has_upper |= IsASCIIUpper(c);
38 ored |= c; 39 ored |= c;
39 } 40 }
40 return has_upper || (ored & ~0x7F); 41 return has_upper || (ored & ~0x7F);
41 } 42 }
42 43
43 static inline bool HasNonASCIIOrUpper(const String& string) { 44 static inline bool HasNonASCIIOrUpper(const String& string) {
44 unsigned length = string.length(); 45 unsigned length = string.length();
45 46
46 if (string.Is8Bit()) 47 if (string.Is8Bit())
47 return HasNonASCIIOrUpper(string.Characters8(), length); 48 return HasNonASCIIOrUpper(string.Characters8(), length);
48 return HasNonASCIIOrUpper(string.Characters16(), length); 49 return HasNonASCIIOrUpper(string.Characters16(), length);
49 } 50 }
50 51
52 // https://dom.spec.whatwg.org/#concept-ordered-set-parser
51 template <typename CharacterType> 53 template <typename CharacterType>
52 inline void SpaceSplitString::Data::CreateVector( 54 inline void SpaceSplitString::Data::CreateVector(
53 const CharacterType* characters, 55 const CharacterType* characters,
54 unsigned length) { 56 unsigned length) {
57 HashSet<AtomicString> token_set;
55 unsigned start = 0; 58 unsigned start = 0;
56 while (true) { 59 while (true) {
57 while (start < length && IsHTMLSpace<CharacterType>(characters[start])) 60 while (start < length && IsHTMLSpace<CharacterType>(characters[start]))
58 ++start; 61 ++start;
59 if (start >= length) 62 if (start >= length)
60 break; 63 break;
61 unsigned end = start + 1; 64 unsigned end = start + 1;
62 while (end < length && IsNotHTMLSpace<CharacterType>(characters[end])) 65 while (end < length && IsNotHTMLSpace<CharacterType>(characters[end]))
63 ++end; 66 ++end;
64 67
65 vector_.push_back(AtomicString(characters + start, end - start)); 68 AtomicString token(characters + start, end - start);
69 if (!token_set.Contains(token)) {
70 token_set.insert(token);
71 vector_.push_back(token);
72 }
66 73
67 start = end + 1; 74 start = end + 1;
68 } 75 }
69 } 76 }
70 77
71 void SpaceSplitString::Data::CreateVector(const String& string) { 78 void SpaceSplitString::Data::CreateVector(const String& string) {
72 unsigned length = string.length(); 79 unsigned length = string.length();
73 80
74 if (string.Is8Bit()) { 81 if (string.Is8Bit()) {
75 CreateVector(string.Characters8(), length); 82 CreateVector(string.Characters8(), length);
(...skipping 27 matching lines...) Expand all
103 DCHECK(!Contains(string)); 110 DCHECK(!Contains(string));
104 vector_.push_back(string); 111 vector_.push_back(string);
105 } 112 }
106 113
107 void SpaceSplitString::Data::Remove(unsigned index) { 114 void SpaceSplitString::Data::Remove(unsigned index) {
108 DCHECK(HasOneRef()); 115 DCHECK(HasOneRef());
109 vector_.erase(index); 116 vector_.erase(index);
110 } 117 }
111 118
112 void SpaceSplitString::Add(const AtomicString& string) { 119 void SpaceSplitString::Add(const AtomicString& string) {
113 // FIXME: add() does not allow duplicates but createVector() does.
114 if (Contains(string)) 120 if (Contains(string))
115 return; 121 return;
116 EnsureUnique(); 122 EnsureUnique();
117 if (data_) 123 if (data_)
118 data_->Add(string); 124 data_->Add(string);
119 else 125 else
120 data_ = Data::Create(string); 126 data_ = Data::Create(string);
121 } 127 }
122 128
123 bool SpaceSplitString::Remove(const AtomicString& string) { 129 bool SpaceSplitString::Remove(const AtomicString& string) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 CreateVector(string); 191 CreateVector(string);
186 } 192 }
187 193
188 SpaceSplitString::Data::Data(const SpaceSplitString::Data& other) 194 SpaceSplitString::Data::Data(const SpaceSplitString::Data& other)
189 : RefCounted<Data>(), vector_(other.vector_) { 195 : RefCounted<Data>(), vector_(other.vector_) {
190 // Note that we don't copy m_keyString to indicate to the destructor that 196 // Note that we don't copy m_keyString to indicate to the destructor that
191 // there's nothing to be removed from the sharedDataMap(). 197 // there's nothing to be removed from the sharedDataMap().
192 } 198 }
193 199
194 } // namespace blink 200 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/frames/sandboxed-iframe-attribute-parsing-03-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698