This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Optimzed vs. readable code
- From: Pierre THIERRY <nowhere dot man at levallois dot eu dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 29 Nov 2005 17:48:38 +0100
- Subject: Optimzed vs. readable code
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