From: Matthew Daiter Date: Wed, 22 May 2019 21:14:13 +0000 (-0400) Subject: Optimize numberOfPermutations X-Git-Tag: yosys-0.9~114^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f0ff31ceea6101cd59ebc6bdff2f253dbbeb06d8;p=yosys.git Optimize numberOfPermutations --- diff --git a/libs/subcircuit/subcircuit.cc b/libs/subcircuit/subcircuit.cc index 7c7236833..e8361a67e 100644 --- a/libs/subcircuit/subcircuit.cc +++ b/libs/subcircuit/subcircuit.cc @@ -320,12 +320,10 @@ class SubCircuit::SolverWorker static int numberOfPermutations(const std::vector &list) { - int numPermutations = 1; - for (int i = 0; i < int(list.size()); i++) { - assert(numPermutations < maxPermutationsLimit); - numPermutations *= i+1; - } - return numPermutations; + constexpr size_t mappedPermutationsSize = 10; + constexpr int mappedPermutations[mappedPermutationsSize] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880}; + assert(list.size() < mappedPermutationsSize); + return mappedPermutations[list.size()]; } static void permutateVectorToMap(std::map &map, const std::vector &list, int idx)