diff mbox

[FFmpeg-devel,2/5] avformat/mxfdec: rework mxf_essence_container_end

Message ID 20190411230920.6630-2-cus@passwd.hu
State Accepted
Commit a5136426a73261e5b5a493f33944be82b6b659c6
Headers show

Commit Message

Marton Balint April 11, 2019, 11:09 p.m. UTC
We find the last essence container much faster if we go through the partitions
backwards...

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mxfdec.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Tomas Härdin April 14, 2019, 3:58 p.m. UTC | #1
fre 2019-04-12 klockan 01:09 +0200 skrev Marton Balint:
> We find the last essence container much faster if we go through the partitions
> backwards...

Good catch

> 
> > Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavformat/mxfdec.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index c3892a1037..18c038c3f6 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -1545,10 +1545,7 @@ static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t of
>   */
>  static int64_t mxf_essence_container_end(MXFContext *mxf, int body_sid)
>  {
> -    int x;
> -    int64_t ret = 0;
> -
> -    for (x = 0; x < mxf->partitions_count; x++) {
> +    for (int x = mxf->partitions_count - 1; x >= 0; x--) {

This is C99, but I think we allow that these days. Maybe someone
objects? Else looks OK

/Tomas
Marton Balint April 28, 2019, 8:14 p.m. UTC | #2
On Sun, 14 Apr 2019, Tomas Härdin wrote:

> fre 2019-04-12 klockan 01:09 +0200 skrev Marton Balint:
>> We find the last essence container much faster if we go through the partitions
>> backwards...
>
> Good catch
>
>> 
>> > Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>>  libavformat/mxfdec.c | 9 +++------
>>  1 file changed, 3 insertions(+), 6 deletions(-)
>> 
>> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
>> index c3892a1037..18c038c3f6 100644
>> --- a/libavformat/mxfdec.c
>> +++ b/libavformat/mxfdec.c
>> @@ -1545,10 +1545,7 @@ static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t of
>>   */
>>  static int64_t mxf_essence_container_end(MXFContext *mxf, int body_sid)
>>  {
>> -    int x;
>> -    int64_t ret = 0;
>> -
>> -    for (x = 0; x < mxf->partitions_count; x++) {
>> +    for (int x = mxf->partitions_count - 1; x >= 0; x--) {
>
> This is C99, but I think we allow that these days. Maybe someone
> objects? Else looks OK

Thanks, applied.

Regards,
Marton
diff mbox

Patch

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index c3892a1037..18c038c3f6 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1545,10 +1545,7 @@  static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t of
  */
 static int64_t mxf_essence_container_end(MXFContext *mxf, int body_sid)
 {
-    int x;
-    int64_t ret = 0;
-
-    for (x = 0; x < mxf->partitions_count; x++) {
+    for (int x = mxf->partitions_count - 1; x >= 0; x--) {
         MXFPartition *p = &mxf->partitions[x];
 
         if (p->body_sid != body_sid)
@@ -1557,10 +1554,10 @@  static int64_t mxf_essence_container_end(MXFContext *mxf, int body_sid)
         if (!p->essence_length)
             return 0;
 
-        ret = p->essence_offset + p->essence_length;
+        return p->essence_offset + p->essence_length;
     }
 
-    return ret;
+    return 0;
 }
 
 /* EditUnit -> absolute offset */