On Wed, Oct 16, 2019 at 9:57 AM Antonio Diaz Diaz <anto...@gnu.org> 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
> Bug-ddrescue@gnu.org
> https://lists.gnu.org/mailman/listinfo/bug-ddrescue

_______________________________________________
Bug-ddrescue mailing list
Bug-ddrescue@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-ddrescue

Reply via email to