]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Make pointers const/restrict where possible in coverage analysis
authorPetr Machata <pmachata@redhat.com>
Mon, 5 Oct 2009 16:55:14 +0000 (18:55 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:10 +0000 (14:55 +0200)
src/dwarflint-coverage.c
src/dwarflint-coverage.h

index 551dd92fc67fef3757145f8dcd00f35fe8d59412..1bec5549add1e9ffc5a67161caa2b86f3a866052 100644 (file)
@@ -35,8 +35,8 @@
 #include <string.h>
 #include <inttypes.h>
 
-static struct cov_range *
-coverage_find (struct coverage *cov, uint64_t start)
+static size_t
+coverage_find (struct coverage const *cov, uint64_t start)
 {
   assert (cov->size > 0);
 
@@ -46,17 +46,17 @@ coverage_find (struct coverage *cov, uint64_t start)
   while (a < b)
     {
       size_t i = (a + b) / 2;
-      struct cov_range *r = cov->ranges + i;
+      struct cov_range const *r = cov->ranges + i;
 
       if (r->start > start)
        b = i;
       else if (r->start < start)
        a = i + 1;
       else
-       return r;
+       return i;
     }
 
-  return cov->ranges + a;
+  return a;
 }
 
 void
@@ -73,7 +73,7 @@ coverage_add (struct coverage *cov, uint64_t start, uint64_t length)
       return;
     }
 
-  struct cov_range *r = coverage_find (cov, start);
+  struct cov_range *r = cov->ranges + coverage_find (cov, start);
 
   struct cov_range *insert = &nr;
   struct cov_range *coalesce = &nr;
@@ -142,7 +142,7 @@ coverage_remove (struct coverage *cov, uint64_t begin, uint64_t length)
   if (cov->size == 0 || begin == end)
     return false;
 
-  struct cov_range *r = coverage_find (cov, begin);
+  struct cov_range *r = cov->ranges + coverage_find (cov, begin);
   struct cov_range *erase_begin = NULL, *erase_end = r; // end exclusive
   bool overlap = false;
 
@@ -206,14 +206,15 @@ coverage_remove (struct coverage *cov, uint64_t begin, uint64_t length)
 }
 
 bool
-coverage_is_covered (struct coverage *cov, uint64_t start, uint64_t length)
+coverage_is_covered (struct coverage const *cov,
+                    uint64_t start, uint64_t length)
 {
   assert (length > 0);
 
   if (cov->size == 0)
     return false;
 
-  struct cov_range *r = coverage_find (cov, start);
+  struct cov_range const *r = cov->ranges + coverage_find (cov, start);
   uint64_t end = start + length;
   if (r < cov->ranges + cov->size)
     if (start >= r->start)
@@ -229,20 +230,21 @@ coverage_is_covered (struct coverage *cov, uint64_t start, uint64_t length)
 }
 
 bool
-coverage_is_overlap (struct coverage *cov, uint64_t start, uint64_t length)
+coverage_is_overlap (struct coverage const *cov,
+                    uint64_t start, uint64_t length)
 {
   if (length == 0 || cov->size == 0)
     return false;
 
   uint64_t end = start + length;
-  bool overlaps (struct cov_range *r)
+  bool overlaps (struct cov_range const *r)
   {
     return (start >= r->start && start < r->start + r->length)
       || (end > r->start && end <= r->start + r->length)
       || (start < r->start && end > r->start + r->length);
   }
 
-  struct cov_range *r = coverage_find (cov, start);
+  struct cov_range const *r = cov->ranges + coverage_find (cov, start);
 
   if (r < cov->ranges + cov->size && overlaps (r))
     return true;
@@ -254,7 +256,8 @@ coverage_is_overlap (struct coverage *cov, uint64_t start, uint64_t length)
 }
 
 bool
-coverage_find_holes (struct coverage *cov, uint64_t start, uint64_t length,
+coverage_find_holes (struct coverage const *cov,
+                    uint64_t start, uint64_t length,
                     bool (*hole)(uint64_t start, uint64_t length, void *data),
                     void *data)
 {
@@ -290,7 +293,7 @@ coverage_find_holes (struct coverage *cov, uint64_t start, uint64_t length,
 }
 
 bool
-coverage_find_ranges (struct coverage *cov,
+coverage_find_ranges (struct coverage const *cov,
                      bool (*cb)(uint64_t start, uint64_t length, void *data),
                      void *data)
 {
@@ -308,7 +311,7 @@ coverage_free (struct coverage *cov)
 }
 
 struct coverage *
-coverage_clone (struct coverage *cov)
+coverage_clone (struct coverage const *cov)
 {
   struct coverage *ret = xmalloc (sizeof (*ret));
   WIPE (*ret);
@@ -317,14 +320,16 @@ coverage_clone (struct coverage *cov)
 }
 
 void
-coverage_add_all (struct coverage *cov, struct coverage *other)
+coverage_add_all (struct coverage *restrict cov,
+                 struct coverage const *restrict other)
 {
   for (size_t i = 0; i < other->size; ++i)
     coverage_add (cov, other->ranges[i].start, other->ranges[i].length);
 }
 
 bool
-coverage_remove_all (struct coverage *cov, struct coverage *other)
+coverage_remove_all (struct coverage *restrict cov,
+                    struct coverage const *restrict other)
 {
   bool ret = false;
   for (size_t i = 0; i < other->size; ++i)
index 9f86020e84a1b309526576772a9a717f8d13e8d2..26b732771b050ca524579264db1c4e1e8b49dbbe 100644 (file)
@@ -71,11 +71,13 @@ struct coverage
   size_t alloc;
 };
 
-struct coverage *coverage_clone (struct coverage *cov) __attribute__ ((malloc));
+struct coverage *coverage_clone (struct coverage const *cov)
+  __attribute__ ((malloc));
 void coverage_free (struct coverage *cov);
 
 void coverage_add (struct coverage *cov, uint64_t start, uint64_t length);
-void coverage_add_all (struct coverage *cov, struct coverage *other);
+void coverage_add_all (struct coverage *__restrict__ cov,
+                      struct coverage const *__restrict__ other);
 
 /* Returns true if something was actually removed, false if whole
    range falls into hole in coverage.  */
@@ -83,21 +85,27 @@ bool coverage_remove (struct coverage *cov, uint64_t start, uint64_t length);
 
 /* Returns true if something was actually removed, false if whole
    range falls into hole in coverage.  */
-bool coverage_remove_all (struct coverage *cov, struct coverage *other);
+bool coverage_remove_all (struct coverage *__restrict__ cov,
+                         struct coverage const *__restrict__ other);
 
 /* Returns true if whole range ADDRESS/LENGTH is covered by COV.
    LENGTH may not be zero.  */
-bool coverage_is_covered (struct coverage *cov, uint64_t start, uint64_t length);
+bool coverage_is_covered (struct coverage const *cov,
+                         uint64_t start, uint64_t length);
 
 /* Returns true if at least some of the range ADDRESS/LENGTH is
    covered by COV.  Zero-LENGTH range never overlaps.  */
-bool coverage_is_overlap (struct coverage *cov, uint64_t start, uint64_t length);
+bool coverage_is_overlap (struct coverage const *cov,
+                         uint64_t start, uint64_t length);
 
-bool coverage_find_holes (struct coverage *cov, uint64_t start, uint64_t length,
-                         bool (*cb)(uint64_t start, uint64_t length, void *data),
+bool coverage_find_holes (struct coverage const *cov,
+                         uint64_t start, uint64_t length,
+                         bool (*cb)(uint64_t start, uint64_t length,
+                                    void *data),
                          void *data);
-bool coverage_find_ranges (struct coverage *cov,
-                         bool (*cb)(uint64_t start, uint64_t length, void *data),
+bool coverage_find_ranges (struct coverage const *cov,
+                         bool (*cb)(uint64_t start, uint64_t length,
+                                    void *data),
                          void *data);
 
 #ifdef __cplusplus