Do not activate strlen assume for debug mode.

This will make debug mode faster.

It also fixes a problem with GCC7 which makes
**release**mode slower (since it called strlen!)
This commit is contained in:
Patrick Pelissier committed 2017-08-06 18:29:09 +02:00
1 parent ccf9bd3ebb
commit f0c03853f8
2 files changed
+9 -1

No files matched your search

+8 -1
View File
@@ -37,13 +37,20 @@
/********************************** INTERNAL ************************************/
/* If within the tests, perform additional checks */
#ifdef STRING_WITHIN_TEST
# define STRINGI_ASSUME(n) M_ASSUME(n)
#else
# define STRINGI_ASSUME(n) (void) 0
#endif
// This macro defines the contract of a string.
// Note: A ==> B is represented as not(A) or B
// Note: use of strlen can slow down a lot the program in some cases.
#define STRING_CONTRACT(v) do { \
M_ASSUME (v != NULL); \
M_ASSUME (v->ptr != NULL || (v->size == 0 && v->alloc == 0)); \
M_ASSUME (v->ptr == NULL || strlen(v->ptr) == v->size); \
STRINGI_ASSUME (v->ptr == NULL || v->size == strlen(v->ptr)); \
M_ASSUME (v->ptr == NULL || v->ptr[v->size] == 0); \
M_ASSUME (v->ptr == NULL || v->size < v->alloc); \
} while (0)
+1
View File
@@ -21,6 +21,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define STRING_WITHIN_TEST
#include "m-string.h"
int main(void)