Skip to content

Commit

Permalink
refactor(crdt): conditionally compile print_data function
Browse files Browse the repository at this point in the history
Wrap print_data function in #ifndef NDEBUG to exclude it from release builds, optimizing performance while retaining debugging capabilities in debug mode.
  • Loading branch information
sinkingsugar committed Oct 8, 2024
1 parent 8e05f7d commit 9cf649a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crdt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,10 @@ class CRDT : public std::enable_shared_from_this<CRDT<K, V, MergeRuleType, Chang
return std::next(write);
}

/// Prints the current data and tombstones for debugging purposes.
///
/// Complexity: O(n * m), where n is the number of records and m is the average number of fields per record
/// Prints the current data and tombstones for debugging purposes.
///
/// Complexity: O(n * m), where n is the number of records and m is the average number of fields per record
#ifndef NDEBUG
constexpr void print_data() const {
std::cout << "Node " << node_id_ << " Data:" << std::endl;
for (const auto &[record_id, record] : data_) {
Expand All @@ -662,6 +663,9 @@ class CRDT : public std::enable_shared_from_this<CRDT<K, V, MergeRuleType, Chang
}
std::cout << std::endl << std::endl;
}
#else
constexpr void print_data() const {}
#endif

// Accessors for testing
// Complexity: O(1)
Expand Down

0 comments on commit 9cf649a

Please sign in to comment.