diff options
author | Matthew Daiter <mdaiter8121@gmail.com> | 2019-05-22 17:14:13 -0400 |
---|---|---|
committer | Matthew Daiter <mdaiter8121@gmail.com> | 2019-05-22 17:29:50 -0400 |
commit | f0ff31ceea6101cd59ebc6bdff2f253dbbeb06d8 (patch) | |
tree | cdcdb3cca74b45ddb243c1f00aecc30c4c90f49b | |
parent | cb24d23b6d450edb3349c9788c06a0a1ee9f0ade (diff) | |
download | yosys-f0ff31ceea6101cd59ebc6bdff2f253dbbeb06d8.tar.gz yosys-f0ff31ceea6101cd59ebc6bdff2f253dbbeb06d8.tar.bz2 yosys-f0ff31ceea6101cd59ebc6bdff2f253dbbeb06d8.zip |
Optimize numberOfPermutations
-rw-r--r-- | libs/subcircuit/subcircuit.cc | 10 |
1 files changed, 4 insertions, 6 deletions
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<std::string> &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<std::string, std::string> &map, const std::vector<std::string> &list, int idx) |