Commit b0c68ce4 authored by Ell's avatar Ell

buffer: add gegl_memeq_zero()

... which checks if a block of memory is fully zeroed.
parent 051ab672
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment