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

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

问题描述

在我之前的问题之后 关于超长函数背后的基本原理,我想提出一个关于 一段代码 我正在为我的研究而学习.它是来自 Linux 内核的一个函数,它很长(412 行)并且很复杂(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.

链接到函数在线资源浏览器

推荐答案

太可怕了,恕我直言.显而易见的一阶修复是让 switch 中的每个 case 都成为对函数的调用.在有人开始抱怨效率之前,让我先说一个词——内联".

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 的 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天全站免登陆