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

Unified Diff: content/public/common/common_param_traits.cc

Issue 2881673002: Avoid heap allocations in IPAddress (Closed)
Patch Set: New constructor 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc ('k') | net/base/ip_address.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/common/common_param_traits.cc
diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc
index 286e6621cc6212cf727ba636c44d4df4a0ba6ceb..2a990c4c3119f0b722962802d60189106ef7c496 100644
--- a/content/public/common/common_param_traits.cc
+++ b/content/public/common/common_param_traits.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/containers/stack_container.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/page_state.h"
#include "content/public/common/referrer.h"
@@ -124,25 +125,30 @@ void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s,
const param_type& p) {
- GetParamSize(s, p.bytes());
+ base::StackVector<uint8_t, 16> bytes;
+ for (uint8_t byte : p.bytes())
+ bytes->push_back(byte);
+ GetParamSize(s, bytes);
}
void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) {
- WriteParam(m, p.bytes());
+ base::StackVector<uint8_t, 16> bytes;
+ for (uint8_t byte : p.bytes())
+ bytes->push_back(byte);
+ WriteParam(m, bytes);
}
bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* p) {
- std::vector<uint8_t> bytes;
+ base::StackVector<uint8_t, 16> bytes;
if (!ReadParam(m, iter, &bytes))
return false;
- if (bytes.size() &&
- bytes.size() != net::IPAddress::kIPv4AddressSize &&
- bytes.size() != net::IPAddress::kIPv6AddressSize) {
+ if (bytes->size() && bytes->size() != net::IPAddress::kIPv4AddressSize &&
+ bytes->size() != net::IPAddress::kIPv6AddressSize) {
return false;
}
- *p = net::IPAddress(bytes);
+ *p = net::IPAddress(bytes->data(), bytes->size());
return true;
}
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc ('k') | net/base/ip_address.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698