mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-10 11:29:55 +00:00
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 :)
This commit is contained in:
parent
c489fb01ca
commit
d48d47e683
1 changed files with 21 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue