9 Star 2 Fork 35

openEuler / libarchive-rust

 / 详情

【代码检视】switch语句转换后可阅读性差

已完成
任务
创建于  
2022-12-12 17:18

代码文件:archive_read_support_format_mtree.rs
问题代码函数:bid_keyword
重构前

        switch (*p) {
	case 'c': keys = keys_c; break;
	case 'd': case 'f': keys = keys_df; break;
	case 'g': keys = keys_g; break;
	case 'i': case 'l': keys = keys_il; break;
	case 'm': keys = keys_m; break;
	case 'n': case 'o': keys = keys_no; break;
	case 'r': keys = keys_r; break;
	case 's': keys = keys_s; break;
	case 't': keys = keys_t; break;
	case 'u': keys = keys_u; break;
	default: return (0);/* Unknown key */
	}

重构后

    unsafe {
        match *p as i32 {
            99 => {
                keys = keys_c.as_ptr()
                /* Unknown key */
            }
            100 | 102 => keys = keys_df.as_ptr(),
            103 => keys = keys_g.as_ptr(),
            105 | 108 => keys = keys_il.as_ptr(),
            109 => keys = keys_m.as_ptr(),
            110 | 111 => keys = keys_no.as_ptr(),
            114 => keys = keys_r.as_ptr(),
            115 => keys = keys_s.as_ptr(),
            116 => keys = keys_t.as_ptr(),
            117 => keys = keys_u.as_ptr(),
            _ => return 0,
        }
    }

重构前的字母是关键字的首字母,重构后难以理解

评论 (3)

hanhuihui 创建了任务

Hi han_hui_hui, welcome to the openEuler Community.
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here.
If you have any questions, please contact the SIG: Base-service, and any of the maintainers: @hexiaowen , @zhujianwei001 , @谢志鹏 , @Monday , @Sora5175 , @Kevin , @lcynju , @huangduirong

openeuler-ci-bot 添加了
 
sig/Base-service
标签

代码文件:archive_read_support_format_mtree.rs
问题代码函数:parse_keyword
重构后很难阅读,类似问题建议仔细排查一遍

为漏改的部分,新提交的pr已解决:!93:解决部分Issue提到的问题

lcynju 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(3)
5329419 openeuler ci bot 1632792936
1
https://gitee.com/openeuler/libarchive-rust.git
git@gitee.com:openeuler/libarchive-rust.git
openeuler
libarchive-rust
libarchive-rust

搜索帮助

344bd9b3 5694891 D2dac590 5694891