//black list bool isLhdcBlacklist = false; isLhdcBlacklist = interop_mtk_match_addr_name(INTEROP_MTK_A2DP_DISABLE_LHDC_CODEC, &peer_address); //Choose bool lhdc_flag = false; if (isLhdcCodec && (A2DP_VendorCodecGetCodecId(p_codec_info) == A2DP_LHDCV5_CODEC_ID)) { switch (strcmp(lhdcv5_support, "false")) { case 0: if (!isLhdcWhitelist || !btif_av_get_lhdc_codec_state()) { lhdc_flag = true; } break; default: if (isLhdcBlacklist || !btif_av_get_lhdc_codec_state()) { lhdc_flag = true; } break; } }优化这段代码
时间: 2024-02-14 14:03:32 浏览: 166
abc.rar_ABC_BOOL CreateProcess_CreateProcess
这段代码可以进行如下优化:
1. 将变量声明和初始化放在一行,更加简洁:
```
bool isLhdcBlacklist = interop_mtk_match_addr_name(INTEROP_MTK_A2DP_DISABLE_LHDC_CODEC, &peer_address);
bool lhdc_flag = false;
```
2. 将 case 0 的情况提前,避免不必要的判断:
```
switch (strcmp(lhdcv5_support, "false")) {
case 0:
if (!isLhdcWhitelist || !btif_av_get_lhdc_codec_state()) {
lhdc_flag = true;
}
break;
default:
if (isLhdcBlacklist || !btif_av_get_lhdc_codec_state()) {
lhdc_flag = true;
}
break;
}
```
3. 将判断条件进行拆分和简化,使代码更加易读:
```
bool isLhdcCodecId = (A2DP_VendorCodecGetCodecId(p_codec_info) == A2DP_LHDCV5_CODEC_ID);
bool isLhdcEnabled = btif_av_get_lhdc_codec_state();
bool isLhdcWhitelistDisabled = !isLhdcWhitelist || !isLhdcEnabled;
bool isLhdcBlacklistEnabled = isLhdcBlacklist || !isLhdcEnabled;
if (isLhdcCodecId) {
switch (strcmp(lhdcv5_support, "false")) {
case 0:
if (isLhdcWhitelistDisabled) {
lhdc_flag = true;
}
break;
default:
if (isLhdcBlacklistEnabled) {
lhdc_flag = true;
}
break;
}
}
```
这样,代码更加简洁、清晰,易于维护。
阅读全文