[augeas-devel] [PATCH 3 of 6] Suppress assert of hash_verify
Jim Meyering
jim at meyering.net
Tue May 6 06:11:28 UTC 2008
David Lutterkort <dlutter at redhat.com> wrote:
> # HG changeset patch
> # User David Lutterkort <dlutter at redhat.com>
> # Date 1210036189 25200
> # Node ID 3a8d71e509488b78bc30ae943bd14044c1805b50
> # Parent 3f3b57d37d78c8bb0f99483b2cec991533fad761
> Suppress assert of hash_verify
>
> Doing the assert(hash_verify(hash)) at various places in hash.c is very
> expensive and slows things down considerably when assertions are turned
> on.
>
> Rather than turning assertions off globally, only do the hash_verify
> asserts when they are explicitly requested by defining HASH_DEBUG_VERIFY
Rather than all of those ugly in-function #ifdefs, how about adding
only say expensive_assert (hash_verify(hash)); statements and
putting this at the top, after the declaration of the function?
#ifdef HASH_DEBUG_VERIFY
# define expensive_assert(expr) assert (expr)
#else
# define expensive_assert(expr) /* empty */
#endif
> diff -r 3f3b57d37d78 -r 3a8d71e50948 src/hash.c
> --- a/src/hash.c Mon May 05 18:09:28 2008 -0700
> +++ b/src/hash.c Mon May 05 18:09:49 2008 -0700
> @@ -199,7 +199,9 @@ static void grow_table(hash_t *hash)
> hash->lowmark *= 2;
> hash->highmark *= 2;
> }
> +#ifdef HASH_DEBUG_VERIFY
> assert (hash_verify(hash));
> +#endif
I.e.,
diff --git a/src/hash.c b/src/hash.c
--- a/src/hash.c
+++ b/src/hash.c
@@ -29,6 +29,12 @@
#define HASH_IMPLEMENTATION
#include "internal.h"
#include "hash.h"
+
+#ifdef HASH_DEBUG_VERIFY
+# define expensive_assert(expr) assert (expr)
+#else
+# define expensive_assert(expr) /* empty */
+#endif
#ifdef KAZLIB_RCSID
static const char rcsid[] = "$Id: hash.c,v 1.36.2.11 2000/11/13 01:36:45 kaz Exp $";
@@ -199,9 +205,7 @@
hash->lowmark *= 2;
hash->highmark *= 2;
}
-#ifdef HASH_DEBUG_VERIFY
- assert (hash_verify(hash));
-#endif
+ expensive_assert (hash_verify(hash));
}
/*
@@ -262,9 +266,7 @@
hash->nchains = nchains;
hash->lowmark /= 2;
hash->highmark /= 2;
-#ifdef HASH_DEBUG_VERIFY
assert (hash_verify(hash));
-#endif
}
@@ -323,9 +325,7 @@
hash->mask = INIT_MASK;
hash->dynamic = 1; /* 7 */
clear_table(hash); /* 8 */
-#ifdef HASH_DEBUG_VERIFY
- assert (hash_verify(hash));
-#endif
+ expensive_assert (hash_verify(hash));
return hash;
}
free(hash);
@@ -424,9 +424,7 @@
hash->mask = compute_mask(nchains); /* 4 */
clear_table(hash); /* 5 */
-#ifdef HASH_DEBUG_VERIFY
- assert (hash_verify(hash));
-#endif
+ expensive_assert (hash_verify(hash));
return hash;
}
@@ -547,9 +545,7 @@
hash->table[chain] = node;
hash->nodecount++;
-#ifdef HASH_DEBUG_VERIFY
- assert (hash_verify(hash));
-#endif
+ expensive_assert (hash_verify(hash));
}
/*
@@ -627,9 +623,7 @@
}
hash->nodecount--;
-#ifdef HASH_DEBUG_VERIFY
- assert (hash_verify(hash));
-#endif
+ expensive_assert (hash_verify(hash));
node->next = NULL; /* 6 */
return node;
@@ -678,9 +672,7 @@
}
hash->nodecount--;
-#ifdef HASH_DEBUG_VERIFY
- assert (hash_verify(hash));
-#endif
+ expensive_assert (hash_verify(hash));
node->next = NULL;
return node;
More information about the augeas-devel
mailing list