[gegl] buffer: add gegl_memeq_zero()
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: add gegl_memeq_zero()
- Date: Fri, 30 Nov 2018 10:40:08 +0000 (UTC)
commit b0c68ce4da747c609ecfac0d6637c6b3e8a5603c
Author: Ell <ell_se yahoo com>
Date: Fri Nov 30 05:25:02 2018 -0500
buffer: add gegl_memeq_zero()
... which checks if a block of memory is fully zeroed.
gegl/buffer/gegl-buffer.h | 13 ++++++++
gegl/buffer/gegl-rectangle.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+)
---
diff --git a/gegl/buffer/gegl-buffer.h b/gegl/buffer/gegl-buffer.h
index 3553ccaef..042d7a286 100644
--- a/gegl/buffer/gegl-buffer.h
+++ b/gegl/buffer/gegl-buffer.h
@@ -755,6 +755,19 @@ void gegl_free (gpointer mem);
*/
gpointer gegl_calloc (gsize size, int n_memb) G_GNUC_MALLOC;
+/**
+ * gegl_memeq_zero: (skip)
+ * @ptr: pointer to the memory block
+ * @size: block size
+ *
+ * Checks if all the bytes of the memory block @ptr, of size @size,
+ * are equal to zero.
+ *
+ * Returns: TRUE if all the bytes are equal to zero.
+ */
+gboolean gegl_memeq_zero (gconstpointer ptr,
+ gsize size);
+
/**
* gegl_memset_pattern: (skip)
* @dst_ptr: pointer to copy to
diff --git a/gegl/buffer/gegl-rectangle.c b/gegl/buffer/gegl-rectangle.c
index 391e2c129..4c8b31afb 100644
--- a/gegl/buffer/gegl-rectangle.c
+++ b/gegl/buffer/gegl-rectangle.c
@@ -304,6 +304,78 @@ gegl_free (gpointer buf)
g_free ((gchar*)buf - *((guint8*)buf -1));
}
+gboolean
+gegl_memeq_zero (gconstpointer ptr,
+ gsize size)
+{
+ const guint8 *p = ptr;
+
+ if (size >= 1 && (guintptr) p & 0x1)
+ {
+ if (*(const guint8 *) p)
+ return FALSE;
+
+ p += 1;
+ size -= 1;
+ }
+
+ if (size >= 2 && (guintptr) p & 0x2)
+ {
+ if (*(const guint16 *) p)
+ return FALSE;
+
+ p += 2;
+ size -= 2;
+ }
+
+ if (size >= 4 && (guintptr) p & 0x4)
+ {
+ if (*(const guint32 *) p)
+ return FALSE;
+
+ p += 4;
+ size -= 4;
+ }
+
+ while (size >= 8)
+ {
+ if (*(const guint64 *) p)
+ return FALSE;
+
+ p += 8;
+ size -= 8;
+ }
+
+ if (size >= 4)
+ {
+ if (*(const guint32 *) p)
+ return FALSE;
+
+ p += 4;
+ size -= 4;
+ }
+
+ if (size >= 2)
+ {
+ if (*(const guint16 *) p)
+ return FALSE;
+
+ p += 2;
+ size -= 2;
+ }
+
+ if (size >= 1)
+ {
+ if (*(const guint8 *) p)
+ return FALSE;
+
+ p += 1;
+ size -= 1;
+ }
+
+ return TRUE;
+}
+
void
gegl_memset_pattern (void * restrict dst_ptr,
const void * restrict src_ptr,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]