Looking at the code there are a lot of improvements that can be made to optimise the code. Profile each case before implementing and check that it indeed improves performance.
Let's chat before implementing anything.
[ ] Don't return copies of objects (alternatives are pointers, references and rvalue references, be careful with the latter. Move semantics take time to get used to.)
[ ] Don't pass by value. Pass by either const reference or pointer (raw or smart) or rvalue reference (move semantics if transferring ownership)
Looking at the code there are a lot of improvements that can be made to optimise the code. Profile each case before implementing and check that it indeed improves performance.
Let's chat before implementing anything.