Blob Blame Raw
From 5b9d5a4f0e351dc73b31507b56334f7ef692f20c Mon Sep 17 00:00:00 2001
Message-Id: <5b9d5a4f0e351dc73b31507b56334f7ef692f20c.1387298827.git.minovotn@redhat.com>
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Tue, 17 Dec 2013 15:16:55 +0100
Subject: [PATCH 03/56] range: add min/max operations on ranges

RH-Author: Michael S. Tsirkin <mst@redhat.com>
Message-id: <1387293161-4085-4-git-send-email-mst@redhat.com>
Patchwork-id: 56308
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 03/57] range: add min/max operations on ranges
Bugzilla: 1034876
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit c5a22c4344f17169bb20e122e9d935c62aedc063)
---
 include/qemu/range.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 include/qemu/range.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/qemu/range.h b/include/qemu/range.h
index 4a0780d..aae9720 100644
--- a/include/qemu/range.h
+++ b/include/qemu/range.h
@@ -17,6 +17,24 @@ struct Range {
     uint64_t end;   /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */
 };
 
+static inline void range_extend(Range *range, Range *extend_by)
+{
+    if (!extend_by->begin && !extend_by->end) {
+        return;
+    }
+    if (!range->begin && !range->end) {
+        *range = *extend_by;
+        return;
+    }
+    if (range->begin > extend_by->begin) {
+        range->begin = extend_by->begin;
+    }
+    /* Compare last byte in case region ends at ~0x0LL */
+    if (range->end - 1 < extend_by->end - 1) {
+        range->end = extend_by->end;
+    }
+}
+
 /* Get last byte of a range from offset + length.
  * Undefined for ranges that wrap around 0. */
 static inline uint64_t range_get_last(uint64_t offset, uint64_t len)
-- 
1.7.11.7