memcmp() is slow?

Maciej Soltysiak solt at dns.toxicfilms.tv
Sat Jan 22 21:31:52 CET 2005


Hi,

I have seen a patch that replaces memcmp() with a few comparison statements.
The log for the change says that memcmp() is slow.

Why is it? Is it just due to the overhead of calling a function and going
through the memory in a loop? Or are there other issues I am not aware of.

Ragards,
Maciej

Below is the mention patch:

trunk/patch-o-matic-ng/nf_conntrack/linux-2.6/include/linux/netfilter/nf_conntrack_tuple.h
2005-01-22 19:05:07 UTC (rev 3607)
@@ -142,19 +142,25 @@
 static inline int nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1,
                                        const struct nf_conntrack_tuple *t2)
 {
-       return (!memcmp(t1->src.u3.all, t2->src.u3.all, sizeof(t1->src.u3.all)))
-              && (t1->src.u.all == t2->src.u.all)
-              && (t1->src.l3num == t2->src.l3num)
-              && (t1->dst.protonum == t2->dst.protonum);
+       return (t1->>src.u3.all[0] == t2->src.u3.all[0] &&
+               t1->>src.u3.all[1] == t2->src.u3.all[1] &&
+               t1->>src.u3.all[2] == t2->src.u3.all[2] &&
+               t1->>src.u3.all[3] == t2->src.u3.all[3] &&
+               t1->>src.u.all == t2->src.u.all &&
+               t1->>src.l3num == t2->src.l3num &&
+               t1->>dst.protonum == t2->dst.protonum);
>  }





More information about the netfilter-devel mailing list