Message ID | 20190327111852.3784-19-andreas.rheinhardt@googlemail.com |
---|---|
State | New |
Headers | show |
On 3/27/2019 12:18 PM, Andreas Rheinhardt via ffmpeg-devel wrote: > By including SimpleBlocks and Blocksgroups twice in the same EbmlSyntax > array (with different semantics), one can reduce the duplication of the > other values. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> > --- > libavformat/matroskadec.c | 13 +++---------- > 1 file changed, 3 insertions(+), 10 deletions(-) > > diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c > index 3adcb3e86d..60f58cefa9 100644 > --- a/libavformat/matroskadec.c > +++ b/libavformat/matroskadec.c > @@ -704,25 +704,18 @@ static const EbmlSyntax matroska_blockgroup[] = { > }; > > static const EbmlSyntax matroska_cluster_parsing[] = { > - { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, > - { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, > { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, > - { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, > - { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, > - { 0 } > -}; > - > -static const EbmlSyntax matroska_cluster_initial[] = { > + { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, > { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, > - { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, > { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, > + { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, > { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, > { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, > { 0 } > }; > > static const EbmlSyntax matroska_cluster_enter[] = { > - { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster_initial } }, > + { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = &matroska_cluster_parsing[2] } }, To avoid breaking this optimisation when the code is changed you might use some static_assert to make sure that matroska_cluster_parsing[2].id is MATROSKA_ID_CLUSTERTIMECODE > { 0 } > }; > > -- > 2.19.2 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Steve Lhomme: > On 3/27/2019 12:18 PM, Andreas Rheinhardt via ffmpeg-devel wrote: >> By including SimpleBlocks and Blocksgroups twice in the same EbmlSyntax >> array (with different semantics), one can reduce the duplication of the >> other values. >> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> >> --- >> libavformat/matroskadec.c | 13 +++---------- >> 1 file changed, 3 insertions(+), 10 deletions(-) >> >> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c >> index 3adcb3e86d..60f58cefa9 100644 >> --- a/libavformat/matroskadec.c >> +++ b/libavformat/matroskadec.c >> @@ -704,25 +704,18 @@ static const EbmlSyntax matroska_blockgroup[] = { >> }; >> static const EbmlSyntax matroska_cluster_parsing[] = { >> - { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, >> offsetof(MatroskaCluster, timecode) }, >> - { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = >> matroska_blockgroup } }, >> { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, >> offsetof(MatroskaBlock, bin) }, >> - { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, >> - { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, >> - { 0 } >> -}; >> - >> -static const EbmlSyntax matroska_cluster_initial[] = { >> + { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = >> matroska_blockgroup } }, >> { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, >> offsetof(MatroskaCluster, timecode) }, >> - { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, >> { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, >> + { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, >> { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, >> { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, >> { 0 } >> }; >> static const EbmlSyntax matroska_cluster_enter[] = { >> - { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = >> matroska_cluster_initial } }, >> + { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = >> &matroska_cluster_parsing[2] } }, > > To avoid breaking this optimisation when the code is changed you might > use some static_assert to make sure that > matroska_cluster_parsing[2].id is MATROSKA_ID_CLUSTERTIMECODE static_assert is actually C11, not C90 (as FFmpeg is), so I think a comment should suffice.
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3adcb3e86d..60f58cefa9 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -704,25 +704,18 @@ static const EbmlSyntax matroska_blockgroup[] = { }; static const EbmlSyntax matroska_cluster_parsing[] = { - { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, - { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, - { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, - { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, - { 0 } -}; - -static const EbmlSyntax matroska_cluster_initial[] = { + { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, - { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, + { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, { 0 } }; static const EbmlSyntax matroska_cluster_enter[] = { - { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster_initial } }, + { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = &matroska_cluster_parsing[2] } }, { 0 } };
By including SimpleBlocks and Blocksgroups twice in the same EbmlSyntax array (with different semantics), one can reduce the duplication of the other values. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> --- libavformat/matroskadec.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)