bug-ddrescue
[Top][All Lists]
Advanced

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

Re: [Bug-ddrescue] [PATCH 2/7] treewide: Replace size() with empty() whe


From: Rosen Penev
Subject: Re: [Bug-ddrescue] [PATCH 2/7] treewide: Replace size() with empty() where appropriate
Date: Wed, 16 Oct 2019 11:38:37 -0700

On Wed, Oct 16, 2019 at 9:57 AM Antonio Diaz Diaz <address@hidden> wrote:
>
> Rosen Penev wrote:
> > The emptiness of a container should be checked using the empty() method
> > instead of the size() method. It is not guaranteed that size() is a
> > constant-time function, and it is generally more efficient and also shows
> > clearer intent to use empty(). Furthermore some containers may implement
> > the empty() method but not implement the size() method. Using empty()
> > whenever possible makes it easier to switch to another container in the
> > future.
>
> For vectors and strings (what ddrescue uses) empty() is defined as 'size()
> == 0'. So nothing is gained with this change.
I agree it's the same. Whether it's cleaner or not is subjective.

if statements evaluate a bool though. Using size like this implicitly
converts it to bool.
>
> Also an automatic replace leaves negations where they are not needed. For
> example
>
> -      if( c == '\n' ) { if( command.size() ) break; else continue; }
> +      if( c == '\n' ) { if( !command.empty() ) break; else continue; }
>
> can be written as
>
> +      if( c == '\n' ) { if( command.empty() ) continue; else break; }
I can resubmit if you would like. My guess is no.
>
> _______________________________________________
> Bug-ddrescue mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/bug-ddrescue



reply via email to

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