|
From: | Antonio Diaz Diaz |
Subject: | Re: [Bug-ddrescue] [PATCH 2/7] treewide: Replace size() with empty() where appropriate |
Date: | Wed, 16 Oct 2019 18:57:38 +0200 |
User-agent: | Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 |
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.
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; }
[Prev in Thread] | Current Thread | [Next in Thread] |