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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 return 0; | 69 return 0; |
70 // It's possible to have hash collisions between arbitrary strings and | 70 // It's possible to have hash collisions between arbitrary strings and |
71 // known identifiers (e.g. "bvvfg" collides with "script"). | 71 // known identifiers (e.g. "bvvfg" collides with "script"). |
72 // However ASSERTs in addNames() guard against there ever being collisions | 72 // However ASSERTs in addNames() guard against there ever being collisions |
73 // between known identifiers. | 73 // between known identifiers. |
74 if (!equal(it->value, characters, length)) | 74 if (!equal(it->value, characters, length)) |
75 return 0; | 75 return 0; |
76 return it->value; | 76 return it->value; |
77 } | 77 } |
78 | 78 |
79 const unsigned kHTMLNamesIndexOffset = 0; | |
Inactive
2013/10/30 18:35:36
These constants were passed to HTMLIdentifier::add
abarth-chromium
2013/10/30 19:30:11
Yeah, this was old tech before we had thread-safe
| |
80 const unsigned kHTMLAttrsIndexOffset = 1000; | |
81 COMPILE_ASSERT(kHTMLAttrsIndexOffset > HTMLTagsCount, kHTMLAttrsIndexOffset_shou ld_be_larger_than_HTMLTagsCount); | |
82 | |
83 const String& HTMLIdentifier::asString() const | 79 const String& HTMLIdentifier::asString() const |
84 { | 80 { |
85 ASSERT(isMainThread()); | 81 ASSERT(isMainThread()); |
86 return m_string; | 82 return m_string; |
87 } | 83 } |
88 | 84 |
89 const StringImpl* HTMLIdentifier::asStringImpl() const | 85 const StringImpl* HTMLIdentifier::asStringImpl() const |
90 { | 86 { |
91 return m_string.impl(); | 87 return m_string.impl(); |
92 } | 88 } |
93 | 89 |
94 void HTMLIdentifier::addNames(const QualifiedName* const* names, unsigned namesC ount, unsigned indexOffset) | 90 void HTMLIdentifier::addNames(const Vector<const QualifiedName*>& names) |
95 { | 91 { |
96 IdentifierTable& table = identifierTable(); | 92 IdentifierTable& table = identifierTable(); |
97 for (unsigned i = 0; i < namesCount; ++i) { | 93 size_t namesCount = names.size(); |
94 for (size_t i = 0; i < namesCount; ++i) { | |
98 StringImpl* name = names[i]->localName().impl(); | 95 StringImpl* name = names[i]->localName().impl(); |
99 unsigned hash = name->hash(); | 96 unsigned hash = name->hash(); |
100 IdentifierTable::AddResult addResult = table.add(hash, name); | 97 IdentifierTable::AddResult addResult = table.add(hash, name); |
101 maxNameLength = std::max(maxNameLength, name->length()); | 98 maxNameLength = std::max(maxNameLength, name->length()); |
102 // 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. |
103 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); |
104 // We expect some hash collisions, but only for identical strings. | 101 // We expect some hash collisions, but only for identical strings. |
105 // Since all of these names are AtomicStrings pointers should be equal. | 102 // Since all of these names are AtomicStrings pointers should be equal. |
106 // 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 |
107 // 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! |
108 ASSERT_UNUSED(addResult, !addResult.isNewEntry || name == addResult.iter ator->value); | 105 ASSERT_UNUSED(addResult, !addResult.isNewEntry || name == addResult.iter ator->value); |
109 } | 106 } |
110 } | 107 } |
111 | 108 |
112 void HTMLIdentifier::init() | 109 void HTMLIdentifier::init() |
113 { | 110 { |
114 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. |
115 static bool isInitialized = false; | 112 static bool isInitialized = false; |
116 if (isInitialized) | 113 if (isInitialized) |
117 return; | 114 return; |
118 isInitialized = true; | 115 isInitialized = true; |
119 | 116 |
120 // FIXME: We should atomize small whitespace (\n, \n\n, etc.) | 117 // FIXME: We should atomize small whitespace (\n, \n\n, etc.) |
121 addNames(getHTMLTags(), HTMLTagsCount, kHTMLNamesIndexOffset); | 118 Vector<const QualifiedName*> HTMLTags; |
122 addNames(getHTMLAttrs(), HTMLAttrsCount, kHTMLAttrsIndexOffset); | 119 getHTMLTags(HTMLTags); |
120 addNames(HTMLTags); | |
121 Vector<const QualifiedName*> HTMLAttrs; | |
122 getHTMLAttrs(HTMLAttrs); | |
123 addNames(HTMLAttrs); | |
123 } | 124 } |
124 | 125 |
125 } | 126 } |
OLD | NEW |