]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virbitmap: Extract clearing of unused bits at the end of the last unit
authorPeter Krempa <pkrempa@redhat.com>
Thu, 17 Oct 2024 11:47:25 +0000 (13:47 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 17 Oct 2024 15:09:24 +0000 (17:09 +0200)
Extract the clearing of the traling bits from 'virBitmapSetAll' into a
new helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/util/virbitmap.c

index 7dc63da6dbdf52cec120e689f0cb4fa32e05b014..35cf729a22c6aa7a460ee24636e34a27b2b294ec 100644 (file)
@@ -757,6 +757,19 @@ virBitmapSize(virBitmap *bitmap)
 }
 
 
+/**
+ * Internal helper that clears the unused bits at the end of the last bitmap unit.
+ */
+static void
+virBitmapClearTail(virBitmap *bitmap)
+{
+    size_t tail = bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT;
+
+    if (tail)
+        bitmap->map[bitmap->map_len - 1] &= -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
+}
+
+
 /**
  * virBitmapSetAll:
  * @bitmap: the bitmap
@@ -765,15 +778,10 @@ virBitmapSize(virBitmap *bitmap)
  */
 void virBitmapSetAll(virBitmap *bitmap)
 {
-    int tail = bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT;
-
     memset(bitmap->map, 0xff,
            bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT));
 
-    /* Ensure tail bits are clear.  */
-    if (tail)
-        bitmap->map[bitmap->map_len - 1] &=
-            -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
+    virBitmapClearTail(bitmap);
 }