Consider some heap optimizations

Hi, I’ve made some heap optimizations, details are here: Reducing CMake heap usage with Heaptrack.
TL;DR: I changed cmListFunction to be a std::shared_ptr and did a couple of another little changes, you can find them all in this branch history. It was mostly small research and heaptrack test for me so I’ll understand if such optimizations wouldn’t be considered significant enough.

Cc: @marc.chevrier @ben.boeckel

@OleksandrKvl thanks! We do occasionally do memory profiling optimizations and it has been a while since the last time, so such improvements would certainly be welcome! Please see CONTRIBUTING.rst for contribution instructions. We can review the details in a merge request.

Ok, I’ll prepare a merge request)

Here it is https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5178