Skip to content

Commit

Permalink
perfect: Refactor deinitializeIfNeeded for Performance and Safety
Browse files Browse the repository at this point in the history
This commit adjusts the deinitializeIfNeeded method in MalomSolutionAccess
to enhance performance and ensure safety. The check for a null pointer
(pp == nullptr) is moved to the beginning of the method. This change
prevents unnecessary cleanup calls and potential double deletion issues,
improving both the performance and robustness of the code. By returning
early when pp is null, we avoid redundant cleanup operations and align
with the intended idempotent nature of the function.

Reference: ggevay/malom#3 (comment)
Change-Id: I6b77af22f99ad500217f1a70145144b33c1f20fb
  • Loading branch information
calcitem committed Dec 25, 2023
1 parent 52cb036 commit c24e536
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/perfect/perfect_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ void MalomSolutionAccess::initializeIfNeeded()

void MalomSolutionAccess::deinitializeIfNeeded()
{
Rules::cleanup();

if (pp == nullptr) {
return;
}

Rules::cleanup();

delete pp;

pp = nullptr;
Expand Down

0 comments on commit c24e536

Please sign in to comment.