OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2013 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 { | 80 { |
81 ASSERT(isMainThread()); | 81 ASSERT(isMainThread()); |
82 return m_string; | 82 return m_string; |
83 } | 83 } |
84 | 84 |
85 const StringImpl* HTMLIdentifier::asStringImpl() const | 85 const StringImpl* HTMLIdentifier::asStringImpl() const |
86 { | 86 { |
87 return m_string.impl(); | 87 return m_string.impl(); |
88 } | 88 } |
89 | 89 |
90 void HTMLIdentifier::addNames(const QualifiedName* const* names, unsigned namesC
ount) | 90 void HTMLIdentifier::addNames(const Vector<const QualifiedName*>& names) |
91 { | 91 { |
92 IdentifierTable& table = identifierTable(); | 92 IdentifierTable& table = identifierTable(); |
93 for (unsigned i = 0; i < namesCount; ++i) { | 93 size_t namesCount = names.size(); |
| 94 for (size_t i = 0; i < namesCount; ++i) { |
94 StringImpl* name = names[i]->localName().impl(); | 95 StringImpl* name = names[i]->localName().impl(); |
95 unsigned hash = name->hash(); | 96 unsigned hash = name->hash(); |
96 IdentifierTable::AddResult addResult = table.add(hash, name); | 97 IdentifierTable::AddResult addResult = table.add(hash, name); |
97 maxNameLength = std::max(maxNameLength, name->length()); | 98 maxNameLength = std::max(maxNameLength, name->length()); |
98 // Ensure we're using the same hashing algorithm to get and set. | 99 // Ensure we're using the same hashing algorithm to get and set. |
99 ASSERT_UNUSED(addResult, !addResult.isNewEntry || HTMLIdentifier::findIf
Known(String(name).charactersWithNullTermination().data(), name->length()) == na
me); | 100 ASSERT_UNUSED(addResult, !addResult.isNewEntry || HTMLIdentifier::findIf
Known(String(name).charactersWithNullTermination().data(), name->length()) == na
me); |
100 // We expect some hash collisions, but only for identical strings. | 101 // We expect some hash collisions, but only for identical strings. |
101 // Since all of these names are AtomicStrings pointers should be equal. | 102 // Since all of these names are AtomicStrings pointers should be equal. |
102 // Note: If you hit this ASSERT, then we had a hash collision among | 103 // Note: If you hit this ASSERT, then we had a hash collision among |
103 // HTMLNames strings, and we need to re-design how we use this hash! | 104 // HTMLNames strings, and we need to re-design how we use this hash! |
104 ASSERT_UNUSED(addResult, !addResult.isNewEntry || name == addResult.iter
ator->value); | 105 ASSERT_UNUSED(addResult, !addResult.isNewEntry || name == addResult.iter
ator->value); |
105 } | 106 } |
106 } | 107 } |
107 | 108 |
108 void HTMLIdentifier::init() | 109 void HTMLIdentifier::init() |
109 { | 110 { |
110 ASSERT(isMainThread()); // Not technically necessary, but this is our curren
t expected usage. | 111 ASSERT(isMainThread()); // Not technically necessary, but this is our curren
t expected usage. |
111 static bool isInitialized = false; | 112 static bool isInitialized = false; |
112 if (isInitialized) | 113 if (isInitialized) |
113 return; | 114 return; |
114 isInitialized = true; | 115 isInitialized = true; |
115 | 116 |
116 // FIXME: We should atomize small whitespace (\n, \n\n, etc.) | 117 // FIXME: We should atomize small whitespace (\n, \n\n, etc.) |
117 addNames(getHTMLTags(), HTMLTagsCount); | 118 Vector<const QualifiedName*> HTMLTags; |
118 addNames(getHTMLAttrs(), HTMLAttrsCount); | 119 getHTMLTags(HTMLTags); |
| 120 addNames(HTMLTags); |
| 121 Vector<const QualifiedName*> HTMLAttrs; |
| 122 getHTMLAttrs(HTMLAttrs); |
| 123 addNames(HTMLAttrs); |
119 } | 124 } |
120 | 125 |
121 } | 126 } |
OLD | NEW |