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

Side by Side Diff: Source/platform/network/HTTPHeaderMap.cpp

Issue 536523002: HTTPHeaderMap: Favor composition over inheritance. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: .. Created 6 years, 3 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 | « Source/platform/network/HTTPHeaderMap.h ('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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 void HTTPHeaderMap::adopt(PassOwnPtr<CrossThreadHTTPHeaderMapData> data) 56 void HTTPHeaderMap::adopt(PassOwnPtr<CrossThreadHTTPHeaderMapData> data)
57 { 57 {
58 clear(); 58 clear();
59 size_t dataSize = data->size(); 59 size_t dataSize = data->size();
60 for (size_t index = 0; index < dataSize; ++index) { 60 for (size_t index = 0; index < dataSize; ++index) {
61 pair<String, String>& header = (*data)[index]; 61 pair<String, String>& header = (*data)[index];
62 set(AtomicString(header.first), AtomicString(header.second)); 62 set(AtomicString(header.first), AtomicString(header.second));
63 } 63 }
64 } 64 }
65 65
66 const AtomicString& HTTPHeaderMap::get(const AtomicString& name) const
67 {
68 return HashMap<AtomicString, AtomicString, CaseFoldingHash>::get(name);
69 }
70
71 HTTPHeaderMap::AddResult HTTPHeaderMap::add(const AtomicString& name, const Atom icString& value)
72 {
73 return HashMap<AtomicString, AtomicString, CaseFoldingHash>::add(name, value );
74 }
75
76 // Adapter that allows the HashMap to take C strings as keys. 66 // Adapter that allows the HashMap to take C strings as keys.
77 struct CaseFoldingCStringTranslator { 67 struct CaseFoldingCStringTranslator {
78 static unsigned hash(const char* cString) 68 static unsigned hash(const char* cString)
79 { 69 {
80 return CaseFoldingHash::hash(cString, strlen(cString)); 70 return CaseFoldingHash::hash(cString, strlen(cString));
81 } 71 }
82 72
83 static bool equal(const AtomicString& key, const char* cString) 73 static bool equal(const AtomicString& key, const char* cString)
84 { 74 {
85 return equalIgnoringCase(key, cString); 75 return equalIgnoringCase(key, cString);
86 } 76 }
87 77
88 static void translate(AtomicString& location, const char* cString, unsigned /*hash*/) 78 static void translate(AtomicString& location, const char* cString, unsigned /*hash*/)
89 { 79 {
90 location = AtomicString(cString); 80 location = AtomicString(cString);
91 } 81 }
92 }; 82 };
93 83
94 const AtomicString& HTTPHeaderMap::get(const char* name) const 84 const AtomicString& HTTPHeaderMap::get(const char* name) const
95 { 85 {
96 const_iterator i = find<CaseFoldingCStringTranslator>(name); 86 const_iterator i = m_headers.find<CaseFoldingCStringTranslator>(name);
97 if (i == end()) 87 if (i == end())
98 return nullAtom; 88 return nullAtom;
99 return i->value; 89 return i->value;
100 } 90 }
101 91
102 bool HTTPHeaderMap::contains(const char* name) const 92 bool HTTPHeaderMap::contains(const char* name) const
103 { 93 {
104 return find<CaseFoldingCStringTranslator>(name) != end(); 94 return m_headers.find<CaseFoldingCStringTranslator>(name) != end();
105 } 95 }
106 96
107 HTTPHeaderMap::AddResult HTTPHeaderMap::add(const char* name, const AtomicString & value) 97 HTTPHeaderMap::AddResult HTTPHeaderMap::add(const char* name, const AtomicString & value)
108 { 98 {
109 return HashMap<AtomicString, AtomicString, CaseFoldingHash>::add<CaseFolding CStringTranslator>(name, value); 99 return m_headers.add<CaseFoldingCStringTranslator>(name, value);
110 } 100 }
111 101
112 } // namespace blink 102 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/network/HTTPHeaderMap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698