Optimzed vs. readable code

Pierre THIERRY nowhere.man@levallois.eu.org
Tue Nov 29 18:05:00 GMT 2005


Hi,

I just noted that the convention for the algorithms I have read in the
GNU STL, when using a starting and ending iterator between which one
want to move, seems to be to increment the first iterator.

We have things like this:

	++first;

And tests like this:

	*first == something

Semantically, that doesn't seem very nice. One can eventually get used to
it, when one knows, but wouldn't it be more judicious for the code to
become more readable, by adding:

	current = first;

Thus, we get:

	++current;

	*current == something

I suppose using the (rather ugly) 'first' as moving iterator has a goal
of optimization, but any decent compiler is now able to optimize this (a
variable initialized with another who is never accessed anymore, locally
to a function), so that this change in the code indeed makes no
difference the the compiled result.

So would a patch with this kind of change be accepted?

Curiously,
Nowhere man
-- 
nowhere.man@levallois.eu.org
OpenPGP 0xD9D50D8A




More information about the Libstdc++ mailing list