Use map to speed up PreprocessingAtomTypes::atomTypeFromName
authorAndrey Alekseenko <al42and@gmail.com>
Mon, 8 Mar 2021 16:38:32 +0000 (16:38 +0000)
committerJoe Jordan <ejjordan12@gmail.com>
Mon, 8 Mar 2021 16:38:32 +0000 (16:38 +0000)
commit12dd719db25f7b2bdcdf3b64d59e0824a2ad369a
treec9f5e9859bb0734baf094bc06d284c9ec2f543de
parent19b531ac2b685b8d4c916402f5e4089c1b3c8d32
Use map to speed up PreprocessingAtomTypes::atomTypeFromName

Previously, we were doing O(numExistingTypes) string comparisons in
PreprocessingAtomTypes::atomTypeFromName.

This significantly slowed down print_bonded function from toputil.cpp,
and, consequently, the pdb2top.

Here, we add an unordered map to store the mapping from type name to
type number, making the whole search O(log(numExistingTypes)), and
avoiding constantly constructing new std::string's from char*'s.

On my machine, this change reduced run time of Pdb2gmx3Test test from ~8
seconds to ~2 seconds.

Closes #3974
src/gromacs/gmxpreprocess/gpp_atomtype.cpp
src/gromacs/gmxpreprocess/tests/cyclic-dna.pdb [deleted file]