monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] Re: using empty() instead of size()


From: Ulf Ochsenfahrt
Subject: Re: [Monotone-devel] Re: using empty() instead of size()
Date: Tue, 23 Sep 2008 13:34:36 +0200
User-agent: Thunderbird 2.0.0.16 (X11/20080724)

Bruce Stephens wrote:
"Derek Scherger" <address@hidden> writes:

Even if size does have to traverse a list to count the elements one would
expect that traversing an *empty* list should be reasonably quick.

Sure, but presumably the extra cost is traversing a non-empty list to
find that it's not empty.  One would hope that an inlined size()
together with a good optimizing compiler might be able to avoid the
cost, but perhaps that's not feasible.

If there is an invalid pointer in the non-empty list, the program can crash. If the compiler optimizes (i.e. removes) the list traversal, the program doesn't crash. Thus, the optimization would change the runtime behavior of the program.

Cheers,

-- Ulf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]