]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
include/uk: Simplify RANGE_OVERLAP macro
authorMarco Schlumpp <marco@unikraft.io>
Tue, 25 Apr 2023 08:05:41 +0000 (10:05 +0200)
committerUnikraft <monkey@unikraft.io>
Mon, 8 May 2023 19:49:15 +0000 (19:49 +0000)
We can simplify the check by observing that there are only two
conditions necessary to check whether a range does *not* overlap:
 - the end of range 0 is before the start of range 1
   [--0--) [--1--)
 - OR the start of range 0 is after the end of range 1
   [--1--) [--0--)
Inverting this gives us a simple condition for checking whether ranges
*do* overlap.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

include/uk/essentials.h

index ee6ff87df1820e945dfc22fdffe02144a9cc28f4..43c7ed30f42917c4786180ac8140050cd049c8ab 100644 (file)
@@ -253,20 +253,12 @@ extern "C" {
 
 /**
  * Tests if two ranges overlap
- * This is the case when at least one of the following conditions is true:
- *  - The start of range 1 is within range 0
- *  - The end of range 1 is within range 0
- *  - The start of range 1 is smaller than the start of range 0 while
- *    the end of range 1 is bigger than the end of range 0
  *  NOTE: The expressions take into account that `base + len` points to
  *        the first value that is outside of a range.
  */
 #define RANGE_OVERLAP(base0, len0, base1, len1)                                \
-       (IN_RANGE((base1), (base0), (len0))                             \
-        || ((((base1) + (len1)) > (base0))                             \
-            && (((base1) + (len1)) <= (base0) + (len0)))               \
-        || (((base1) <= (base0))                                       \
-            && (((base1) + (len1)) >= ((base0) + (len0)))))
+       (((((base1) + (len1)) > (base0))) &&                            \
+       ((base1) < ((base0) + (len0))))
 
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))