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

Side by Side Diff: net/interfaces/ip_address_struct_traits.h

Issue 2881673002: Avoid heap allocations in IPAddress (Closed)
Patch Set: copys 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 #ifndef NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_ 5 #ifndef NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_
6 #define NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_ 6 #define NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_
7 7
8 #include "mojo/public/cpp/bindings/struct_traits.h" 8 #include "mojo/public/cpp/bindings/struct_traits.h"
9 #include "net/base/ip_address.h" 9 #include "net/base/ip_address.h"
10 #include "net/interfaces/ip_address.mojom.h" 10 #include "net/interfaces/ip_address.mojom.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 template <> 13 template <>
14 struct StructTraits<net::interfaces::IPAddressDataView, net::IPAddress> { 14 struct StructTraits<net::interfaces::IPAddressDataView, net::IPAddress> {
15 static const std::vector<uint8_t>& address(const net::IPAddress& ip_address) { 15 static const std::vector<uint8_t> address(const net::IPAddress& ip_address) {
16 return ip_address.bytes(); 16 // TODO(rch): avoid creating a vector here.
17 return ip_address.CopyBytesToVector();
17 } 18 }
18 19
19 static bool Read(net::interfaces::IPAddressDataView obj, net::IPAddress* out); 20 static bool Read(net::interfaces::IPAddressDataView obj, net::IPAddress* out);
20 }; 21 };
21 22
22 } // namespace mojo 23 } // namespace mojo
23 24
24 #endif // NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_ 25 #endif // NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698