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

Side by Side Diff: net/interfaces/ip_address_struct_traits.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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "net/interfaces/ip_address_struct_traits.h" 5 #include "net/interfaces/ip_address_struct_traits.h"
6 6
7 namespace mojo { 7 namespace mojo {
8 // static 8 // static
9 bool StructTraits<net::interfaces::IPAddressDataView, net::IPAddress>::Read( 9 bool StructTraits<net::interfaces::IPAddressDataView, net::IPAddress>::Read(
10 net::interfaces::IPAddressDataView data, 10 net::interfaces::IPAddressDataView data,
11 net::IPAddress* out) { 11 net::IPAddress* out) {
12 std::vector<uint8_t> bytes; 12 std::vector<uint8_t> bytes;
13 if (!data.ReadAddress(&bytes)) 13 if (!data.ReadAddress(&bytes))
14 return false; 14 return false;
15 15
16 *out = net::IPAddress(bytes); 16 *out = net::IPAddress(bytes.data(), bytes.size());
17 return out->IsValid(); 17 return out->IsValid();
18 } 18 }
19 19
20 } // namespace mojo 20 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698