From 49c4e367e9601f2c877b844bb004119b54ee89fe Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 20 May 2009 11:12:43 +0200 Subject: [PATCH] adapter: avoid comparisions in fast path Small tweaks to reduce the number of useless compares in loops. --- libs/gst/base/gstadapter.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index cc7f15617f..67d5b0aa1d 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -244,7 +244,7 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip, g = adapter->buflist; buf = g->data; bsize = GST_BUFFER_SIZE (buf); - while (skip >= bsize) { + while (G_UNLIKELY (skip >= bsize)) { skip -= bsize; g = g_slist_next (g); buf = g->data; @@ -257,14 +257,14 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip, dest += csize; /* second step, copy remainder */ - while (size > 0) { + do { g = g_slist_next (g); buf = g->data; csize = MIN (GST_BUFFER_SIZE (buf), size); memcpy (dest, GST_BUFFER_DATA (buf), csize); size -= csize; dest += csize; - } + } while (size > 0); } /** @@ -747,7 +747,7 @@ gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask, g = adapter->buflist; buf = g->data; bsize = GST_BUFFER_SIZE (buf); - while (skip >= bsize) { + while (G_UNLIKELY (skip >= bsize)) { skip -= bsize; g = g_slist_next (g); buf = g->data; @@ -761,7 +761,7 @@ gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask, state = ~pattern; /* now find data */ - while (size > 0) { + do { bsize = MIN (bsize, size); for (i = bsize; i; i--) { state = ((state << 8) | *bdata++); @@ -771,15 +771,17 @@ gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask, } } size -= bsize; - if (size > 0) { - /* nothing found yet, go to next buffer */ - offset += bsize; - g = g_slist_next (g); - buf = g->data; - bsize = GST_BUFFER_SIZE (buf); - bdata = GST_BUFFER_DATA (buf); - } - } + if (size == 0) + break; + + /* nothing found yet, go to next buffer */ + offset += bsize; + g = g_slist_next (g); + buf = g->data; + bsize = GST_BUFFER_SIZE (buf); + bdata = GST_BUFFER_DATA (buf); + } while (TRUE); + /* nothing found */ offset = -1; found: