简体   繁体   English

对此if语句哪个更好的表达?

[英]Which is a better expression for this if statement?

I've been told of a patch for ffmpeg that fixes an issue when streaming to FLV players. 有人告诉我ffmpeg的修补程序,该修补程序解决了向FLV播放器流式传输时的问题。

Around line 2314 of rtmpproto.c there is the following expression: rtmpproto.c的第2314行周围有以下表达式:

if (rt->flv_header_bytes < 11)
            break;

The fix is to change it to include this additional requirement: 解决方法是将其更改为包括以下附加要求:

if (rt->flv_header_bytes < 11 && !rt->flv_off)
            break;

However I'm curious about the logic of this statement. 但是,我对此声明的逻辑感到好奇。 The first statement checks to see if the FLV header is less than 11 bytes, but wouldn't it be more efficient to check to see if the flv stream is turned on first before it checks how many bytes big the header is? 第一条语句检查FLV标头是否少于11个字节,但是在检查flv流在标头有多少个字节之前是否先打开flv流是否更有效?

if (!rt->flv_off && rt->flv_header_bytes < 11)
            break;

Alternatively what about changing the statement to be like so? 另外,如何将语句更改为这样?

if (rt->flv_off || (!rt->flv_off && rt->flv_header_bytes < 11)
                break;

Would that be more efficient or could it break the code somehow? 这会更有效还是会以某种方式破坏代码?

It depends on which condition fails most often, and whether or not the compiler respects the order in which you've typed the conditions. 它取决于哪个条件最常失败,以及编译器是否遵守您键入条件的顺序。 Assuming the later is true (a big assumption), it's probably more efficient to check the header size first, since presumably the FLV player is usually on. 假设后者是正确的(一个很大的假设),则首先检查标头大小可能会更有效,因为大概FLV播放器通常处于打开状态。

More specifics would be necessary for a complete evaluation...although none of this probably matters anyway, since (a) the time "wasted" is almost certainly insignificant and (b) the compiler will most likely do a much better job optimizing than you will. 完整的评估需要更多细节……尽管无论如何这都无关紧要,因为(a)“浪费”的时间几乎可以肯定是微不足道的,并且(b)编译器最有可能在优化方面比您做得更好将。

If you want to use an OR as in your third statement, just apply DeMorgan's law and write 如果要在第三条陈述中使用OR,则只需应用DeMorgan定律并写

if(rt->flv_off || rt->flv_header_bytes >= 11)

But again, this isn't something to really worry about. 但是,这并不是真正要担心的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM