summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-05-20 12:48:41 +0200
committerWim Taymans <wim@metal.(none)>2009-05-20 12:48:41 +0200
commitfd76e4fc939346a4e2406027b6ba9ae3c02fd7df (patch)
tree05a7c3f14c58e481751b9f1007af7e4b2762da3d
parentf3ff7ad055440a64f0fe3ad304883e5da5f37c0d (diff)
adapter: potentially save a memcpy in _take
Directly use the assembled_data in _take() functions when we can instead of copying it out.
-rw-r--r--libs/gst/base/gstadapter.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c
index 66088b5591..b846a3f494 100644
--- a/libs/gst/base/gstadapter.c
+++ b/libs/gst/base/gstadapter.c
@@ -113,7 +113,7 @@
#include <string.h>
/* default size for the assembled data buffer */
-#define DEFAULT_SIZE 16
+#define DEFAULT_SIZE 4096
GST_DEBUG_CATEGORY_STATIC (gst_adapter_debug);
#define GST_CAT_DEFAULT gst_adapter_debug
@@ -528,14 +528,17 @@ gst_adapter_take (GstAdapter * adapter, guint nbytes)
if (G_UNLIKELY (nbytes > adapter->size))
return NULL;
- data = g_malloc (nbytes);
-
- /* we have enough assembled data, copy from there */
+ /* we have enough assembled data, take from there */
if (adapter->assembled_len >= nbytes) {
GST_LOG_OBJECT (adapter, "taking %u bytes already assembled", nbytes);
- memcpy (data, adapter->assembled_data, nbytes);
+ data = adapter->assembled_data;
+ /* allocate new data, assembled_len will be set to 0 in the flush below */
+ adapter->assembled_data = g_malloc (adapter->assembled_size);
} else {
+ /* we need to allocate and copy. We could potentially copy bytes from the
+ * assembled data before doing the copy_into */
GST_LOG_OBJECT (adapter, "taking %u bytes by collection", nbytes);
+ data = g_malloc (nbytes);
copy_into_unchecked (adapter, data, adapter->skip, nbytes);
}
@@ -608,13 +611,19 @@ gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
}
}
- buffer = gst_buffer_new_and_alloc (nbytes);
-
/* we have enough assembled data, copy from there */
if (adapter->assembled_len >= nbytes) {
GST_LOG_OBJECT (adapter, "taking %u bytes already assembled", nbytes);
- memcpy (GST_BUFFER_DATA (buffer), adapter->assembled_data, nbytes);
+ buffer = gst_buffer_new ();
+ GST_BUFFER_SIZE (buffer) = nbytes;
+ GST_BUFFER_DATA (buffer) = adapter->assembled_data;
+ GST_BUFFER_MALLOCDATA (buffer) = adapter->assembled_data;
+ /* flush will set the assembled_len to 0 */
+ adapter->assembled_data = g_malloc (adapter->assembled_size);
} else {
+ /* we need to allocate and copy. We could potentially copy bytes from the
+ * assembled data before doing the copy_into */
+ buffer = gst_buffer_new_and_alloc (nbytes);
GST_LOG_OBJECT (adapter, "taking %u bytes by collection", nbytes);
copy_into_unchecked (adapter, GST_BUFFER_DATA (buffer), skip, nbytes);
}