On Tue, May 30, 2006 at 05:32:19PM +0000, Angus Leeming wrote:
> Andre Poenitz <[EMAIL PROTECTED]> writes:
> > > +void InsetCaption::setLabel(LCursor & cur) const
> > > +{
> > > + // Set caption label _only_ if the cursor is in _this_ float:
> > > + if (cur.top().text() == &text_) {
> > > +         string s; 
> > > +         size_t i = cur.depth();
> > > +                 while (i > 0) {
> > > +                         --i;
> 
> > Probably not your doing, but: Indentation of the loop is off.
> > Apart from it can be shortened by two lines:
> >  for (size_t i = cur.depth(); i--; )
> 
> Now you're just being evil, André ;-) At least be explicit about the exit
> condition. I *think* that your code is equivalent to:
> 
>    for (size_t i = cur.depth(); i > 0; i--)
> 
> I *think* I've convinced myself that the two for statements are the same, but
> I've definitely bruised some brain cells in the process.

Probably the ones you'd have needed... Or I lost some of mine...

My loop's first iteration has  i == depth() - 1, yours i == depth().

Depending on the loop contents this might make a difference.

Andre', considering  'for (size_t i = cur.depth(); i--; )' being an
idiom.

PS: And of course, 

 'for (int i = (int) cur.depth(); --i >= 0; )' 

produce the tightest code on any compiler I know. 

Which means, that  std::<stuff>::size() returning 'size_t' instead
of a signed type violates the "don't waste cycles on features you don't
need" principle.

PPS: Does it show that I've been forced to use disassemblers lately?

PPPS: Qt could be much faster.

Reply via email to