]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: shortcut RR comparisons if pointers match
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Dec 2015 16:28:50 +0000 (17:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Dec 2015 10:28:01 +0000 (11:28 +0100)
When iterating through RR lists we frequently end up comparing RRs and
RR keys with themselves, hence att a minor optimization to check ptr
values first, before doing a deep comparison.

src/resolve/resolved-dns-rr.c

index 934a18334c85e9164e0353b2f2c35556e7e56349..260a2a3bd66b2c1dfab4e9be0ee07164292cf9db 100644 (file)
@@ -168,6 +168,9 @@ bool dns_resource_key_is_address(const DnsResourceKey *key) {
 int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
         int r;
 
+        if (a == b)
+                return 1;
+
         r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
         if (r <= 0)
                 return r;
@@ -187,6 +190,9 @@ int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord
         assert(key);
         assert(rr);
 
+        if (key == rr->key)
+                return 1;
+
         /* Checks if an rr matches the specified key. If a search
          * domain is specified, it will also be checked if the key
          * with the search domain suffixed might match the RR. */
@@ -503,6 +509,9 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
         assert(a);
         assert(b);
 
+        if (a == b)
+                return 1;
+
         r = dns_resource_key_equal(a->key, b->key);
         if (r <= 0)
                 return r;
@@ -1090,6 +1099,9 @@ DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i) {
 
 bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b) {
 
+        if (a == b)
+                return true;
+
         if (!a != !b)
                 return false;