summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2009-10-21 20:44:33 +0200
committerEdward Hervey <bilboed@bilboed.com>2009-10-21 21:04:45 +0200
commitd48d47e68365990d7c66782225f7fddf7efde86e (patch)
tree00ba413d31bf3fd02a64521ab08e5e16e1dc0c3a
parentc489fb01caaac5815c2a49bc3de41eb10405f05a (diff)
typefind: speed up mxf_type_find over 300 times for worst case scenarios
* memcmp is expensive and was being abused, reduce calling it by checking the first byte. * iterating one byte at at time over 64 kbites introduces a certain overhead, therefore we now do it in chunks of 1024 bytes And I do mean over 300 times. The average instruction call per mxf_type_find was previously 785685 and it's now down to 2458 :)
-rw-r--r--gst/typefind/gsttypefindfunctions.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c
index 77edb7e58..d394de006 100644
--- a/gst/typefind/gsttypefindfunctions.c
+++ b/gst/typefind/gsttypefindfunctions.c
@@ -2697,28 +2697,35 @@ mxf_type_find (GstTypeFind * tf, gpointer ununsed)
DataScanCtx c = { 0, NULL, 0 };
while (c.offset <= MXF_MAX_PROBE_LENGTH) {
- if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
+ guint i;
+ if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
break;
- if (memcmp (c.data, partition_pack_key, 13) == 0) {
- /* Header partition pack? */
- if (c.data[13] != 0x02)
- goto advance;
+ /* look over in chunks of 1kbytes to avoid too much overhead */
- /* Partition status */
- if (c.data[14] >= 0x05)
- goto advance;
+ for (i = 0; i < 1024 - 16; i++) {
+ /* Check first byte before calling more expensive memcmp function */
+ if (G_UNLIKELY (c.data[0] == 0x06
+ && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
+ /* Header partition pack? */
+ if (c.data[i + 13] != 0x02)
+ goto advance;
- /* Reserved, must be 0x00 */
- if (c.data[15] != 0x00)
- goto advance;
+ /* Partition status */
+ if (c.data[i + 14] >= 0x05)
+ goto advance;
- gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
- return;
+ /* Reserved, must be 0x00 */
+ if (c.data[i + 15] != 0x00)
+ goto advance;
+
+ gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
+ return;
+ }
}
advance:
- data_scan_ctx_advance (tf, &c, 1);
+ data_scan_ctx_advance (tf, &c, 1024 - 16);
}
}