Changeset 51566 in webkit
- Timestamp:
- Dec 1, 2009 4:05:30 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r51555 r51566 1 2009-12-01 Jens Alfke <snej@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Added variants of find/contains/add that allow a foreign key type to be used. 6 This will allow AtomicString-keyed maps to be queried by C string without 7 having to create a temporary AtomicString (see HTTPHeaderMap.) 8 The code for this is adapted from the equivalent in HashSet.h. 9 10 * wtf/HashMap.h: 11 (WTF::HashMap::find): 12 (WTF::HashMap::contains): 13 (WTF::HashMap::add): 14 * wtf/HashSet.h: Changed "method" to "function member" in a comment. 15 1 16 2009-12-01 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> 2 17 -
trunk/JavaScriptCore/wtf/HashMap.h
r45120 r51566 84 84 MappedType take(const KeyType&); // efficient combination of get with remove 85 85 86 // An alternate version of find() that finds the object by hashing and comparing 87 // with some other type, to avoid the cost of type conversion. HashTranslator 88 // must have the following function members: 89 // static unsigned hash(const T&); 90 // static bool equal(const ValueType&, const T&); 91 template<typename T, typename HashTranslator> iterator find(const T&); 92 template<typename T, typename HashTranslator> const_iterator find(const T&) const; 93 template<typename T, typename HashTranslator> bool contains(const T&) const; 94 95 // An alternate version of add() that finds the object by hashing and comparing 96 // with some other type, to avoid the cost of type conversion if the object is already 97 // in the table. HashTranslator must have the following function members: 98 // static unsigned hash(const T&); 99 // static bool equal(const ValueType&, const T&); 100 // static translate(ValueType&, const T&, unsigned hashCode); 101 template<typename T, typename HashTranslator> pair<iterator, bool> add(const T&, const MappedType&); 102 86 103 private: 87 104 pair<iterator, bool> inlineAdd(const KeyType&, const MappedType&); … … 108 125 }; 109 126 127 template<typename ValueType, typename ValueTraits, typename T, typename Translator> 128 struct HashMapTranslatorAdapter { 129 typedef typename ValueType::first_type KeyType; 130 typedef typename ValueType::second_type MappedType; 131 132 static unsigned hash(const T& key) { return Translator::hash(key); } 133 static bool equal(const KeyType& a, const T& b) { return Translator::equal(a, b); } 134 static void translate(ValueType& location, const T& key, const MappedType&, unsigned hashCode) 135 { 136 Translator::translate(location.first, key, hashCode); 137 } 138 }; 139 110 140 template<typename T, typename U, typename V, typename W, typename X> 111 141 inline void HashMap<T, U, V, W, X>::swap(HashMap& other) … … 172 202 { 173 203 return m_impl.contains(key); 204 } 205 206 template<typename T, typename U, typename V, typename W, typename X> 207 template<typename TYPE, typename HashTranslator> 208 inline typename HashMap<T, U, V, W, X>::iterator 209 HashMap<T, U, V, W, X>::find(const TYPE& value) 210 { 211 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 212 return m_impl.template find<TYPE, Adapter>(value); 213 } 214 215 template<typename T, typename U, typename V, typename W, typename X> 216 template<typename TYPE, typename HashTranslator> 217 inline typename HashMap<T, U, V, W, X>::const_iterator 218 HashMap<T, U, V, W, X>::find(const TYPE& value) const 219 { 220 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 221 return m_impl.template find<TYPE, Adapter>(value); 222 } 223 224 template<typename T, typename U, typename V, typename W, typename X> 225 template<typename TYPE, typename HashTranslator> 226 inline bool 227 HashMap<T, U, V, W, X>::contains(const TYPE& value) const 228 { 229 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 230 return m_impl.template contains<TYPE, Adapter>(value); 174 231 } 175 232 … … 192 249 } 193 250 return result; 251 } 252 253 template<typename T, typename U, typename V, typename W, typename X> 254 template<typename TYPE, typename HashTranslator> 255 pair<typename HashMap<T, U, V, W, X>::iterator, bool> 256 HashMap<T, U, V, W, X>::add(const TYPE& key, const MappedType& value) 257 { 258 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 259 return m_impl.template addPassingHashCode<TYPE, MappedType, Adapter>(key, value); 194 260 } 195 261 -
trunk/JavaScriptCore/wtf/HashSet.h
r48259 r51566 82 82 // An alternate version of add() that finds the object by hashing and comparing 83 83 // with some other type, to avoid the cost of type conversion if the object is already 84 // in the table. HashTranslator must have the following methods:84 // in the table. HashTranslator must have the following function members: 85 85 // static unsigned hash(const T&); 86 86 // static bool equal(const ValueType&, const T&); -
trunk/WebCore/ChangeLog
r51565 r51566 1 2009-12-01 Jens Alfke <snej@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Add convenience methods to Element and QualifiedName that take 6 char* instead of AtomicString, in preparation for removing the 7 implicit conversion between the two types (30187). 8 https://bugs.webkit.org/show_bug.cgi?id=31749 9 10 * dom/Element.cpp: 11 (WebCore::Element::setCStringAttribute): Equivalent to setAttribute. 12 * dom/Element.h: 13 * dom/QualifiedName.cpp: 14 (WebCore::QualifiedName::init): Shared impl of both constructors 15 (WebCore::QualifiedName::QualifiedName): New c'tor taking char*. 16 * dom/QualifiedName.h: 17 * platform/network/HTTPHeaderMap.cpp: 18 (WebCore::CaseFoldingCStringTranslator): Enables lookup by C string 19 (WebCore::HTTPHeaderMap::get): New variant that takes C string 20 (WebCore::HTTPHeaderMap::contains): New variant that takes C string 21 (WebCore::HTTPHeaderMap::add): New variant that takes C string 22 * platform/network/HTTPHeaderMap.h: 23 (WebCore::HTTPHeaderMap::get): 24 (WebCore::HTTPHeaderMap::add): 25 * platform/network/ResourceRequestBase.cpp: 26 (WebCore::ResourceRequestBase::httpHeaderField): New variant that takes C string 27 * platform/network/ResourceRequestBase.h: 28 (WebCore::ResourceRequestBase::setHTTPHeaderField): Use symbolic names for headers 29 * platform/network/ResourceResponseBase.cpp: 30 (WebCore::ResourceResponseBase::httpHeaderField): New variant that takes C string 31 * platform/network/ResourceResponseBase.h: 32 1 33 2009-12-01 Alexey Proskuryakov <ap@apple.com> 2 34 -
trunk/WebCore/dom/Element.cpp
r50763 r51566 137 137 setAttribute(name, value, ec); 138 138 } 139 140 void Element::setCStringAttribute(const QualifiedName& name, const char* cStringValue) 141 { 142 ExceptionCode ec; 143 setAttribute(name, AtomicString(cStringValue), ec); 144 } 139 145 140 146 void Element::setBooleanAttribute(const QualifiedName& name, bool b) -
trunk/WebCore/dom/Element.h
r48723 r51566 168 168 void setAttribute(const QualifiedName&, const AtomicString& value); 169 169 void setBooleanAttribute(const QualifiedName& name, bool); 170 // Please don't use setCStringAttribute in performance-sensitive code; 171 // use a static AtomicString value instead to avoid the conversion overhead. 172 void setCStringAttribute(const QualifiedName&, const char* cStringValue); 170 173 171 174 virtual NamedNodeMap* attributes() const; -
trunk/WebCore/dom/QualifiedName.cpp
r49798 r51566 52 52 static QNameSet* gNameCache; 53 53 54 QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const AtomicString& n)54 void QualifiedName::init(const AtomicString& p, const AtomicString& l, const AtomicString& n) 55 55 { 56 56 if (!gNameCache) … … 61 61 if (!addResult.second) 62 62 m_impl->ref(); 63 } 64 65 QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const AtomicString& n) 66 { 67 init(p, l, n); 68 } 69 70 QualifiedName::QualifiedName(const AtomicString& p, const char* l, const AtomicString& n) 71 { 72 init(p, AtomicString(l), n); 63 73 } 64 74 -
trunk/WebCore/dom/QualifiedName.h
r50464 r51566 58 58 59 59 QualifiedName(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI); 60 QualifiedName(const AtomicString& prefix, const char* localName, const AtomicString& namespaceURI); 60 61 ~QualifiedName() { deref(); } 61 62 #ifdef QNAME_DEFAULT_CONSTRUCTOR … … 89 90 90 91 private: 92 void init(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI); 91 93 void ref() const { m_impl->ref(); } 92 94 void deref(); -
trunk/WebCore/platform/network/HTTPHeaderMap.cpp
r49160 r51566 60 60 } 61 61 } 62 63 // Adapter that allows the HashMap to take C strings as keys. 64 struct CaseFoldingCStringTranslator { 65 static unsigned hash(const char* cString) 66 { 67 return CaseFoldingHash::hash(cString, strlen(cString)); 68 } 69 70 static bool equal(const AtomicString& key, const char* cString) 71 { 72 return equalIgnoringCase(key, cString); 73 } 74 75 static void translate(AtomicString& location, const char* cString, unsigned /*hash*/) 76 { 77 location = AtomicString(cString); 78 } 79 }; 80 81 String HTTPHeaderMap::get(const char* name) const 82 { 83 const_iterator i = find<const char*, CaseFoldingCStringTranslator>(name); 84 if (i == end()) 85 return String(); 86 return i->second; 87 } 88 89 bool HTTPHeaderMap::contains(const char* name) const 90 { 91 return find<const char*, CaseFoldingCStringTranslator>(name) != end(); 92 } 93 94 pair<HTTPHeaderMap::iterator, bool> HTTPHeaderMap::add(const char* name, const String& value) 95 { 96 return HashMap<AtomicString, String, CaseFoldingHash>::add<const char*, CaseFoldingCStringTranslator>(name, value); 97 } 62 98 63 99 } // namespace WebCore -
trunk/WebCore/platform/network/HTTPHeaderMap.h
r40162 r51566 46 46 47 47 void adopt(std::auto_ptr<CrossThreadHTTPHeaderMapData>); 48 49 String get(const AtomicString& name) const 50 { 51 return HashMap<AtomicString, String, CaseFoldingHash>::get(name); 52 } 53 54 pair<iterator, bool> add(const AtomicString& name, const String& value) 55 { 56 return HashMap<AtomicString, String, CaseFoldingHash>::add(name, value); 57 } 58 59 // Alternate accessors that are faster than converting the char* to AtomicString first. 60 bool contains(const char*) const; 61 String get(const char*) const; 62 pair<iterator, bool> add(const char* name, const String& value); 63 48 64 }; 49 65 -
trunk/WebCore/platform/network/ResourceRequestBase.cpp
r50226 r51566 209 209 } 210 210 211 String ResourceRequestBase::httpHeaderField(const char* name) const 212 { 213 updateResourceRequest(); 214 215 return m_httpHeaderFields.get(name); 216 } 217 211 218 void ResourceRequestBase::setHTTPHeaderField(const AtomicString& name, const String& value) 212 219 { … … 217 224 if (url().protocolInHTTPFamily()) 218 225 m_platformRequestUpdated = false; 226 } 227 228 void ResourceRequestBase::setHTTPHeaderField(const char* name, const String& value) 229 { 230 setHTTPHeaderField(AtomicString(name), value); 219 231 } 220 232 -
trunk/WebCore/platform/network/ResourceRequestBase.h
r51179 r51566 80 80 const HTTPHeaderMap& httpHeaderFields() const; 81 81 String httpHeaderField(const AtomicString& name) const; 82 String httpHeaderField(const char* name) const; 82 83 void setHTTPHeaderField(const AtomicString& name, const String& value); 84 void setHTTPHeaderField(const char* name, const String& value); 83 85 void addHTTPHeaderField(const AtomicString& name, const String& value); 84 86 void addHTTPHeaderFields(const HTTPHeaderMap& headerFields); -
trunk/WebCore/platform/network/ResourceResponseBase.cpp
r49160 r51566 234 234 235 235 String ResourceResponseBase::httpHeaderField(const AtomicString& name) const 236 { 237 lazyInit(); 238 239 return m_httpHeaderFields.get(name); 240 } 241 242 String ResourceResponseBase::httpHeaderField(const char* name) const 236 243 { 237 244 lazyInit(); -
trunk/WebCore/platform/network/ResourceResponseBase.h
r45461 r51566 72 72 73 73 String httpHeaderField(const AtomicString& name) const; 74 String httpHeaderField(const char* name) const; 74 75 void setHTTPHeaderField(const AtomicString& name, const String& value); 75 76 const HTTPHeaderMap& httpHeaderFields() const;
Note: See TracChangeset
for help on using the changeset viewer.