mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Decrease number of pointer derefs in connection.c
@ 2005-12-08 22:36 Jesper Juhl
  2005-12-09 10:18 ` David Howells
  0 siblings, 1 reply; 2+ messages in thread
From: Jesper Juhl @ 2005-12-08 22:36 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: David Howells, Andrew Morton, Jesper Juhl

Hi,

Here's a small patch to decrease the number of pointer derefs in
net/rxrpc/connection.c

Benefits of the patch:
 - Fewer pointer dereferences should make the code slightly faster.
 - Size of generated code is smaller
 - improved readability

Please consider applying.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

 net/rxrpc/connection.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

orig:
   text    data     bss     dec     hex filename
   7146      40       4    7190    1c16 net/rxrpc/connection.o

patched:
   text    data     bss     dec     hex filename
   7140      40       4    7184    1c10 net/rxrpc/connection.o

--- linux-2.6.15-rc5-git1-orig/net/rxrpc/connection.c	2005-10-28 02:02:08.000000000 +0200
+++ linux-2.6.15-rc5-git1/net/rxrpc/connection.c	2005-12-08 20:29:15.000000000 +0100
@@ -220,6 +220,7 @@ int rxrpc_connection_lookup(struct rxrpc
 {
 	struct rxrpc_connection *conn, *candidate = NULL;
 	struct list_head *_p;
+	struct sk_buff *pkt = msg->pkt;
 	int ret, fresh = 0;
 	__be32 x_epoch, x_connid;
 	__be16 x_port, x_servid;
@@ -229,10 +230,10 @@ int rxrpc_connection_lookup(struct rxrpc
 	_enter("%p{{%hu}},%u,%hu",
 	       peer,
 	       peer->trans->port,
-	       ntohs(msg->pkt->h.uh->source),
+	       ntohs(pkt->h.uh->source),
 	       ntohs(msg->hdr.serviceId));
 
-	x_port		= msg->pkt->h.uh->source;
+	x_port		= pkt->h.uh->source;
 	x_epoch		= msg->hdr.epoch;
 	x_clflag	= msg->hdr.flags & RXRPC_CLIENT_INITIATED;
 	x_connid	= htonl(ntohl(msg->hdr.cid) & RXRPC_CIDMASK);
@@ -267,7 +268,7 @@ int rxrpc_connection_lookup(struct rxrpc
 		/* fill in the specifics */
 		candidate->addr.sin_family	= AF_INET;
 		candidate->addr.sin_port	= x_port;
-		candidate->addr.sin_addr.s_addr = msg->pkt->nh.iph->saddr;
+		candidate->addr.sin_addr.s_addr = pkt->nh.iph->saddr;
 		candidate->in_epoch		= x_epoch;
 		candidate->out_epoch		= x_epoch;
 		candidate->in_clientflag	= RXRPC_CLIENT_INITIATED;
@@ -675,6 +676,7 @@ int rxrpc_conn_receive_call_packet(struc
 				   struct rxrpc_message *msg)
 {
 	struct rxrpc_message *pmsg;
+	struct dst_entry *dst;
 	struct list_head *_p;
 	unsigned cix, seq;
 	int ret = 0;
@@ -710,10 +712,10 @@ int rxrpc_conn_receive_call_packet(struc
 
 	call->pkt_rcv_count++;
 
-	if (msg->pkt->dst && msg->pkt->dst->dev)
+	dst = msg->pkt->dst;
+	if (dst && dst->dev)
 		conn->peer->if_mtu =
-			msg->pkt->dst->dev->mtu -
-			msg->pkt->dst->dev->hard_header_len;
+			dst->dev->mtu - dst->dev->hard_header_len;
 
 	/* queue on the call in seq order */
 	rxrpc_get_message(msg);



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Decrease number of pointer derefs in connection.c
  2005-12-08 22:36 [PATCH] Decrease number of pointer derefs in connection.c Jesper Juhl
@ 2005-12-09 10:18 ` David Howells
  0 siblings, 0 replies; 2+ messages in thread
From: David Howells @ 2005-12-09 10:18 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: Linux Kernel Mailing List, David Howells, Andrew Morton

Jesper Juhl <jesper.juhl@gmail.com> wrote:

> Benefits of the patch:
>  - Fewer pointer dereferences should make the code slightly faster.
>  - Size of generated code is smaller
>  - improved readability

I'm a little surprised that it makes it faster or smaller: I'd've thought that
the gcc optimiser would be up to caching the pointer; in fact, if it made any
difference, I'd've thought it'd make it larger, slower and consume more stack
space as the compiler would then have to carry the extra variable around.

OTOH, compiler's are black magic, possibly even blacker than kernels, so who
knows...

David

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-12-09 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-08 22:36 [PATCH] Decrease number of pointer derefs in connection.c Jesper Juhl
2005-12-09 10:18 ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome