| > True, but it is cleaner to reorganize the code into several functions and use the return value to propagate across layers if needed. I disagree. Having to jump to another function definition which is inline is a bigger mental block than following a goto. The large amount of arguments you'd need to pass might also be a barrier, as is the mental overhead of checking to see if this function might be called from elsewhere. But reasonable people can disagree on this point. I suggest you try to clean up the function yourself and see if your function-ed version is in any way improved. > Why? If there is a new/delete pair anywhere, it should have been an object. The case we want is that we have a large array of pairwise collisions. This is a temporary array used inside the method. If we ever have more than this, we need a new (contiguous) array. Are you suggesting that the code should have done something like this? template<typename T> class TempArray { T* storage; void resize(int n) { delete[] storage; storage = new T[n]; }; I mean, sure, it's a very minor cleanup. It changes like, two lines though, and makes us have to access the array through an awkward ->storage pointer. Not ideal IMO. > codegen should be on par as a new/delete pair. Here's modern MSVC. Let's play "spot the difference": https://gcc.godbolt.org/z/KqR-LN I'm not even doing anything but allocating the vector / array. It took me 2 minutes to navigate to godbolt and type this in. Don't just say "should be"... test it yourself! |
It is a good illustration of why debug stl builds are such hot garbage though...