Skip to content

Commit

Permalink
perms.cc: Replace new and delete[] with OCTAVE_LOCAL_BUFFER
Browse files Browse the repository at this point in the history
* libinterp/corefcn/perms.cc (GetPerms, GetPermsNoSort): Use OCTAVE_LOCAL_BUFFER
instead of operator new and operator delete[].
  • Loading branch information
mmuetzel committed Nov 5, 2023
1 parent 912c6e6 commit 13ad59a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions libinterp/corefcn/perms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ GetPerms (const Array<T> &ar_in, bool uniq_v, bool do_sort = false)
double nr = Factorial (m);

// Setup index vector filled from 0..m-1
int* myvidx = new int[m];
OCTAVE_LOCAL_BUFFER (int, myvidx, m);
for (int i = 0; i < m; i++)
myvidx[i] = i;

Expand Down Expand Up @@ -114,8 +114,6 @@ GetPerms (const Array<T> &ar_in, bool uniq_v, bool do_sort = false)
}
while (std::next_permutation (myvidx, myvidx + m, std::greater<int> ()));

delete[] myvidx;

return res;
}

Expand All @@ -131,7 +129,7 @@ GetPermsNoSort (const Array<T> &ar_in, bool uniq_v = false)
double nr = Factorial (m);

// Setup index vector filled from 0..m-1
int* myvidx = new int[m];
OCTAVE_LOCAL_BUFFER (int, myvidx, m);
for (int i = 0; i < m; i++)
myvidx[i] = i;

Expand Down Expand Up @@ -179,8 +177,6 @@ GetPermsNoSort (const Array<T> &ar_in, bool uniq_v = false)
}
while (std::next_permutation (myvidx, myvidx + m, std::greater<int> ()));

delete[] myvidx;

return res;
}

Expand Down

0 comments on commit 13ad59a

Please sign in to comment.