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

Unified Diff: net/quic/platform/impl/quic_ip_address_impl.cc

Issue 2881673002: Avoid heap allocations in IPAddress (Closed)
Patch Set: Done 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
Index: net/quic/platform/impl/quic_ip_address_impl.cc
diff --git a/net/quic/platform/impl/quic_ip_address_impl.cc b/net/quic/platform/impl/quic_ip_address_impl.cc
index e0c58f14ec87d4601c10b8d955831e48b3ff2f29..6dd60845ceb00ecd7377ecfddea76b1896a86100 100644
--- a/net/quic/platform/impl/quic_ip_address_impl.cc
+++ b/net/quic/platform/impl/quic_ip_address_impl.cc
@@ -4,6 +4,7 @@
#include "net/quic/platform/impl/quic_ip_address_impl.h"
+#include "base/containers/stack_container.h"
#include "net/base/address_family.h"
#include "net/quic/platform/api/quic_bug_tracker.h"
@@ -107,9 +108,10 @@ bool QuicIpAddressImpl::FromPackedString(const char* data, size_t length) {
QUIC_BUG << "Invalid packed IP address of length " << length;
return false;
}
- std::vector<uint8_t> ip(length);
+ base::StackVector<uint8_t, 16> ip;
+ ip->resize(length);
memcpy(&ip[0], data, length);
- ip_address_ = IPAddress(ip);
+ ip_address_ = IPAddress(ip->data(), ip->size());
eroman 2017/05/19 22:00:07 Delete the three lines above, and change this one
Ryan Hamilton 2017/05/20 03:21:44 Done. (needs a reinterpret_cast though. Thanks, C+
return true;
}

Powered by Google App Engine
This is Rietveld 408576698