]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1975] Small optimisation
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 14 Jun 2012 12:45:58 +0000 (14:45 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 14 Jun 2012 12:45:58 +0000 (14:45 +0200)
Don't compute the number of matched labels at the first match, there's
nothing to compare against anyway. We hope that there'll be only one one
partial match in practice.

src/lib/datasrc/list.cc

index f9a95ab42e748ab1a16388c8e7a18c5baf7d86e9..ab3bb6088f548a34492aae14e59de2189d0ecd3b 100644 (file)
@@ -73,11 +73,13 @@ ConfigurableClientList::find(const dns::Name& name, bool want_exact_match,
     struct MutableResult {
         MutableResult() :
             datasrc_client(NULL),
-            matched_labels(0)
+            matched_labels(0),
+            matched(false)
         { }
         DataSourceClient* datasrc_client;
         ZoneFinderPtr finder;
         uint8_t matched_labels;
+        bool matched;
         operator FindResult() const {
             // Conversion to the right result. If we return this, there was
             // a partial match at best.
@@ -108,13 +110,25 @@ ConfigurableClientList::find(const dns::Name& name, bool want_exact_match,
                 if (!want_exact_match) {
                     // In case we have a partial match, check if it is better
                     // than what we have. If so, replace it.
-                    const uint8_t labels(
-                        result.zone_finder->getOrigin().getLabelCount());
-                    if (labels > candidate.matched_labels) {
+                    //
+                    // We don't need the labels at the first partial match,
+                    // we have nothing to compare with. So we don't get it
+                    // (as a performance) and hope we will not need it at all.
+                    const uint8_t labels(candidate.matched ?
+                        result.zone_finder->getOrigin().getLabelCount() : 0);
+                    if (candidate.matched && candidate.matched_labels == 0) {
+                        // But if the hope turns out to be false, we need to
+                        // compute it for the first match anyway.
+                        candidate.matched_labels = candidate.finder->
+                            getOrigin().getLabelCount();
+                    }
+                    if (labels > candidate.matched_labels ||
+                        !candidate.matched) {
                         // This one is strictly better. Replace it.
                         candidate.datasrc_client = info.data_src_client_;
                         candidate.finder = result.zone_finder;
                         candidate.matched_labels = labels;
+                        candidate.matched = true;
                     }
                 }
                 break;