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

Side by Side Diff: content/public/common/common_param_traits.cc

Issue 2881673002: Avoid heap allocations in IPAddress (Closed)
Patch Set: DCHECK 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/common/common_param_traits.h" 5 #include "content/public/common/common_param_traits.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "content/public/common/content_constants.h" 9 #include "content/public/common/content_constants.h"
10 #include "content/public/common/page_state.h" 10 #include "content/public/common/page_state.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 *p = net::IPEndPoint(address, port); 117 *p = net::IPEndPoint(address, port);
118 return true; 118 return true;
119 } 119 }
120 120
121 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { 121 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
122 LogParam("IPEndPoint:" + p.ToString(), l); 122 LogParam("IPEndPoint:" + p.ToString(), l);
123 } 123 }
124 124
125 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s, 125 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s,
126 const param_type& p) { 126 const param_type& p) {
127 GetParamSize(s, p.bytes()); 127 for (uint8_t byte : p.bytes())
128 GetParamSize(s, byte);
128 } 129 }
129 130
130 void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) { 131 void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) {
131 WriteParam(m, p.bytes()); 132 for (uint8_t byte : p.bytes())
133 WriteParam(m, byte);
132 } 134 }
133 135
134 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, 136 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m,
135 base::PickleIterator* iter, 137 base::PickleIterator* iter,
136 param_type* p) { 138 param_type* p) {
137 std::vector<uint8_t> bytes; 139 std::vector<uint8_t> bytes;
138 if (!ReadParam(m, iter, &bytes)) 140 if (!ReadParam(m, iter, &bytes))
139 return false; 141 return false;
140 if (bytes.size() && 142 if (bytes.size() &&
141 bytes.size() != net::IPAddress::kIPv4AddressSize && 143 bytes.size() != net::IPAddress::kIPv4AddressSize &&
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 201 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
200 #include "content/public/common/common_param_traits_macros.h" 202 #include "content/public/common/common_param_traits_macros.h"
201 } // namespace IPC 203 } // namespace IPC
202 204
203 // Generate param traits log methods. 205 // Generate param traits log methods.
204 #include "ipc/param_traits_log_macros.h" 206 #include "ipc/param_traits_log_macros.h"
205 namespace IPC { 207 namespace IPC {
206 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 208 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
207 #include "content/public/common/common_param_traits_macros.h" 209 #include "content/public/common/common_param_traits_macros.h"
208 } // namespace IPC 210 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698