This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]