From bebefe2afe73b82e2a0c40a13534a6c2046d7e2b Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Thu, 19 Feb 2015 09:53:55 +0200 Subject: [PATCH] net: return reference to hw_feature instead of copying the structure I noticed that tcp::hw_features() is not inlined and copies the structure to a caller. The function takes ~1.5% in httpd profiling. --- net/ip.hh | 2 +- net/net.hh | 2 +- net/tcp.hh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ip.hh b/net/ip.hh index 3c8c139f1b..75f02b7d44 100644 --- a/net/ip.hh +++ b/net/ip.hh @@ -368,7 +368,7 @@ public: tcp& get_tcp() { return *_tcp._tcp; } ipv4_udp& get_udp() { return _udp; } void register_l4(proto_type id, ip_protocol* handler); - net::hw_features hw_features() { return _netif->hw_features(); } + const net::hw_features& hw_features() const { return _netif->hw_features(); } static bool needs_frag(packet& p, ip_protocol_num proto_num, net::hw_features hw_features); void learn(ethernet_address l2, ipv4_address l3) { _arp.learn(l2, l3); diff --git a/net/net.hh b/net/net.hh index db7c954073..96cf20ff7b 100644 --- a/net/net.hh +++ b/net/net.hh @@ -119,7 +119,7 @@ private: public: explicit interface(std::shared_ptr dev); ethernet_address hw_address() { return _hw_address; } - net::hw_features hw_features() { return _hw_features; } + const net::hw_features& hw_features() const { return _hw_features; } subscription register_l3(eth_protocol_num proto_num, std::function (packet p, ethernet_address from)> next, std::function forward); diff --git a/net/tcp.hh b/net/tcp.hh index 91c0b9e061..648846a0cc 100644 --- a/net/tcp.hh +++ b/net/tcp.hh @@ -591,7 +591,7 @@ public: bool forward(forward_hash& out_hash_data, packet& p, size_t off); listener listen(uint16_t port, size_t queue_length = 100); future connect(socket_address sa); - net::hw_features hw_features() { return _inet._inet.hw_features(); } + const net::hw_features& hw_features() const { return _inet._inet.hw_features(); } future<> poll_tcb(ipaddr to, lw_shared_ptr tcb); private: void send_packet_without_tcb(ipaddr from, ipaddr to, packet p);