News:

Simutrans Chat Room
Where cool people of Simutrans can meet up.

[cleanup patch] Don't use min() in quickstone

Started by neroden, July 11, 2010, 07:02:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

neroden

While attempting to clean up types in preparation for switching to template-based min/max functions, I found that the code in quickstone_tpl.h was actually cleaner and simpler without the use of min().  This rearranges the logic of the array extension, with the nice side effect of moving the main code out by one indentation level (with the error case in an if clause) -- and manages to avoid long arithmetic, too!

No behavior change.  Patch attached.

Amelek

#1
btw,

+      memcpy( newdata, data, sizeof(T*)*size );

this isnt a safe way to copy classes in c++.



nevermind, i missed the fact that its pointer array  :-[

prissi

I saw no harm in min, but I have also no aversions against your code. What is the problem with min?

neroden

Quote from: prissi on July 11, 2010, 08:24:46 PM
I saw no harm in min, but I have also no aversions against your code. What is the problem with min?

There is no problem with min().... yet.  I have been hoping to switch over to a template version of min() which does typechecking, instead of a macro which doesn't.  In the long run std::min() could be used. 

So I've been discovering all the places where min(type A, type B) was called, which causes trouble for a type-safe version of min().  Of course min(type A, type A) is always fine.

In some of these place, it's appropriate to just put in a type cast.  But in others it's cleaner to *remove* typecasts, and this is one of those places.