这个内核功能可以更具可读性吗? (学术研究需要的想法!) [英] Can this kernel function be more readable? (Ideas needed for an academic research!)

查看:85
本文介绍了这个内核功能可以更具可读性吗? (学术研究需要的想法!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循我之前的问题关于极长函数背后的原理,我想提出一个关于 MCC索引的133).基本上,这是一个长且嵌套的switch语句

Following my previous question regarding the rationale behind extremely long functions, I would like to present a specific question regarding a piece of code I am studying for my research. It's a function from the Linux Kernel which is quite long (412 lines) and complicated (an MCC index of 133). Basically, it's a long and nested switch statement

坦率地说,我想不出任何办法来改善这种混乱状况.调度表看起来既庞大又效率低下,任何子例程调用都将需要数量难以想象的参数,才能覆盖足够多的代码段.

Frankly, I can't think of any way to improve this mess. A dispatch table seems both huge and inefficient, and any subroutine call would require an inconceivable number of arguments in order to cover a large-enough segment of code.

您是否认为可以在不损失效率的情况下以更易读的方式重写此函数?如果没有,代码对您来说可读吗?

Do you think of any way this function can be rewritten in a more readable way, without losing efficiency? If not, does the code seem readable to you?

不用说,无论是在这里还是在提交的论文中,我研究中出现的所有答案都将得到充分的肯定.

Needless to say, any answer that will appear in my research will be given full credit - both here and in the submitted paper.

链接到在线源浏览器

推荐答案

完全糟糕,恕我直言.显而易见的一阶解决方案是使开关中的每种情况都调用一个函数.在有人开始抱怨效率问题之前,我只想说一个字-内联".

Utterly horrible, IMHO. The obvious first-order fix is to make each case in the switch a call to a function. And before anyone starts mumbling about efficiency, let me just say one word - "inlining".

编辑:此代码是Linux FPU模拟器的一部分吗?如果是这样,这是非常古老的代码,这是使Linux在没有FPU的Intel芯片(如386)上运行的一种技巧.如果是这样,除了历史学家之外,这可能不适合学者们研究!

Is this code part of the Linux FPU emulator by any chance? If so this is very old code that was a hack to get linux to work on Intel chips like the 386 which didn't have an FPU. If it is, it's probably not a suitable study for academics, except for historians!

这篇关于这个内核功能可以更具可读性吗? (学术研究需要的想法!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆