复杂的if else,switch case 条件判断,用表驱动方法如何优化
程序代码:
void UserSet_Effect(User * const me) { int TempEffect; int machine; const INIT_STRUCT *AmpTab =NULL; if(me->Night) TempEffect = eEq_Night; else TempEffect = me->Effect; machine = me->channel_search; { if(TempEffect == eEq_Off || TempEffect == eEq_On){ switch (machine) { case channel_RL: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_only_aux; } else{ AmpTab = AmpDrcVaOn_SB_only_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_only_aux; } else{ AmpTab = AmpDrcVaOn_SB_only_digital; } } break; case channel_RL_Sub: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_sub_aux; } else{ AmpTab = AmpDrcVaOn_SB_sub_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_sub_aux; } else{ AmpTab = AmpDrcVaOn_SB_sub_digital; } } break; case channel_RL_RLs: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_surr_aux; } else{ AmpTab = AmpDrcVaOn_SB_surr_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_surr_aux; } else{ AmpTab = AmpDrcVaOn_SB_surr_digital; } } break; case channel_RL_RLs_Sub: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_sub_surr_aux; } else{ AmpTab = AmpDrcVaOn_SB_sub_surr_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcVaOn_SB_sub_surr_aux; } else{ AmpTab = AmpDrcVaOn_SB_sub_surr_digital; } } break; } }else if(TempEffect == eEq_Night){ switch (machine) { case channel_RL: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_only_aux; } else{ AmpTab = AmpDrcNight_SB_only_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_only_aux; } else{ AmpTab = AmpDrcNight_SB_only_digital; } } break; case channel_RL_Sub: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_sub_aux; } else{ AmpTab = AmpDrcNight_SB_sub_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_sub_aux; } else{ AmpTab = AmpDrcNight_SB_sub_digital; } } break; case channel_RL_RLs: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_surr_aux; } else{ AmpTab = AmpDrcNight_SB_surr_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_surr_aux; } else{ AmpTab = AmpDrcNight_SB_surr_digital; } } break; case channel_RL_RLs_Sub: if ((me->BitstreamInfo == (BITSTREAM_CH_L | BITSTREAM_CH_R)) || (me->BitstreamInfo == BITSTREAM_CH_L) || (me->BitstreamInfo == BITSTREAM_CH_R) ){ if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_sub_surr_aux; } else{ AmpTab = AmpDrcNight_SB_sub_surr_digital; } }else { if (me->UserSrc_tbl[me->iSrc] == eAp_AUX_Src){ AmpTab = AmpDrcNight_SB_sub_surr_aux; } else{ AmpTab = AmpDrcNight_SB_sub_surr_digital; } } break; } } if (AmpTab != NULL) UserAmp(AmpTab, 1); } }
[此贴子已经被作者于2022-1-10 09:59编辑过]