adapter: avoid comparisions in fast path

Small tweaks to reduce the number of useless compares in loops.
This commit is contained in:
Wim Taymans 2009-05-20 11:12:43 +02:00 committed by Wim Taymans
parent 23314ddefb
commit 49c4e367e9

View file

@ -244,7 +244,7 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip,
g = adapter->buflist; g = adapter->buflist;
buf = g->data; buf = g->data;
bsize = GST_BUFFER_SIZE (buf); bsize = GST_BUFFER_SIZE (buf);
while (skip >= bsize) { while (G_UNLIKELY (skip >= bsize)) {
skip -= bsize; skip -= bsize;
g = g_slist_next (g); g = g_slist_next (g);
buf = g->data; buf = g->data;
@ -257,14 +257,14 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip,
dest += csize; dest += csize;
/* second step, copy remainder */ /* second step, copy remainder */
while (size > 0) { do {
g = g_slist_next (g); g = g_slist_next (g);
buf = g->data; buf = g->data;
csize = MIN (GST_BUFFER_SIZE (buf), size); csize = MIN (GST_BUFFER_SIZE (buf), size);
memcpy (dest, GST_BUFFER_DATA (buf), csize); memcpy (dest, GST_BUFFER_DATA (buf), csize);
size -= csize; size -= csize;
dest += csize; dest += csize;
} } while (size > 0);
} }
/** /**
@ -747,7 +747,7 @@ gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask,
g = adapter->buflist; g = adapter->buflist;
buf = g->data; buf = g->data;
bsize = GST_BUFFER_SIZE (buf); bsize = GST_BUFFER_SIZE (buf);
while (skip >= bsize) { while (G_UNLIKELY (skip >= bsize)) {
skip -= bsize; skip -= bsize;
g = g_slist_next (g); g = g_slist_next (g);
buf = g->data; buf = g->data;
@ -761,7 +761,7 @@ gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask,
state = ~pattern; state = ~pattern;
/* now find data */ /* now find data */
while (size > 0) { do {
bsize = MIN (bsize, size); bsize = MIN (bsize, size);
for (i = bsize; i; i--) { for (i = bsize; i; i--) {
state = ((state << 8) | *bdata++); state = ((state << 8) | *bdata++);
@ -771,15 +771,17 @@ gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask,
} }
} }
size -= bsize; size -= bsize;
if (size > 0) { if (size == 0)
/* nothing found yet, go to next buffer */ break;
offset += bsize;
g = g_slist_next (g); /* nothing found yet, go to next buffer */
buf = g->data; offset += bsize;
bsize = GST_BUFFER_SIZE (buf); g = g_slist_next (g);
bdata = GST_BUFFER_DATA (buf); buf = g->data;
} bsize = GST_BUFFER_SIZE (buf);
} bdata = GST_BUFFER_DATA (buf);
} while (TRUE);
/* nothing found */ /* nothing found */
offset = -1; offset = -1;
found: found: