Browse Source

[2433] Avoid copy of the callbacks

When passing an argument to boost::bind by value, it was copied
(obviously, since it allowed removal of const). Add the const and use a
pointer to avoid the copy of possibly large object.
Michal 'vorner' Vaner 12 years ago
parent
commit
7bea86f909
2 changed files with 8 additions and 8 deletions
  1. 6 6
      src/lib/dns/zone_checker.cc
  2. 2 2
      src/lib/dns/zone_checker.h

+ 6 - 6
src/lib/dns/zone_checker.cc

@@ -170,15 +170,15 @@ checkNS(const Name& zone_name, const RRClass& zone_class,
 // The following two are simple wrapper of checker callbacks so checkZone()
 // can also remember any critical errors.
 void
-errorWrapper(const string& reason, ZoneCheckerCallbacks& callbacks,
+errorWrapper(const string& reason, const ZoneCheckerCallbacks* callbacks,
              bool* had_error) {
     *had_error = true;
-    callbacks.error(reason);
+    callbacks->error(reason);
 }
 
 void
-warnWrapper(const string& reason, ZoneCheckerCallbacks& callbacks) {
-    callbacks.warn(reason);
+warnWrapper(const string& reason, const ZoneCheckerCallbacks* callbacks) {
+    callbacks->warn(reason);
 }
 }
 
@@ -188,8 +188,8 @@ checkZone(const Name& zone_name, const RRClass& zone_class,
           const ZoneCheckerCallbacks& callbacks) {
     bool had_error = false;
     ZoneCheckerCallbacks my_callbacks(
-        boost::bind(errorWrapper, _1, callbacks, &had_error),
-        boost::bind(warnWrapper, _1, callbacks));
+        boost::bind(errorWrapper, _1, &callbacks, &had_error),
+        boost::bind(warnWrapper, _1, &callbacks));
 
     checkSOA(zone_name, zone_class, zone_rrsets, my_callbacks);
     checkNS(zone_name, zone_class, zone_rrsets, my_callbacks);

+ 2 - 2
src/lib/dns/zone_checker.h

@@ -59,7 +59,7 @@ public:
     /// thrown from the callback.
     ///
     /// \param reason Textual representation of the reason for the error.
-    void error(const std::string& reason) {
+    void error(const std::string& reason) const {
         if (!error_callback_.empty()) {
             error_callback_(reason);
         }
@@ -71,7 +71,7 @@ public:
     /// thrown from the callback.
     ///
     /// \param reason Textual representation of the reason for the issue.
-    void warn(const std::string& reason) {
+    void warn(const std::string& reason) const {
         if (!warn_callback_.empty())
             warn_callback_(reason);
     }