if(m_bZoomViaProtocol) { ret = sendMsg(msgInfo(SID_GENERALMOVE_STOPCONTINUOUSMOVE, pPtzOperationCmd, PTZ_STOP)); } else { if (PTZ_OPT_ZOOM_WIDE != pPtzOperationCmd->cmd || PTZ_OPT_ZOOM_TELE != pPtzOperationCmd->cmd) { ret = sendMsg(msgInfo(SID_GENERALMOVE_STOPCONTINUOUSMOVE, pPtzOperationCmd, PTZ_STOP)); } }
时间: 2024-02-20 19:01:02 浏览: 68
RAE RET程序.rar_RAE RET程序_RET程序_apartmentbh3_rae ret_电调天线
5星 · 资源好评率100%
可以通过以下两种方式来优化这段代码:
1. 减少重复代码
可以将两个分支中重复的代码提取出来,放到条件语句外面,避免重复编写代码。例如:
```
bool stopContinuousMove = true;
if (m_bZoomViaProtocol) {
stopContinuousMove = true;
} else {
if (PTZ_OPT_ZOOM_WIDE == pPtzOperationCmd->cmd || PTZ_OPT_ZOOM_TELE == pPtzOperationCmd->cmd) {
stopContinuousMove = false;
}
}
if (stopContinuousMove) {
ret = sendMsg(msgInfo(SID_GENERALMOVE_STOPCONTINUOUSMOVE, pPtzOperationCmd, PTZ_STOP));
}
```
2. 简化条件语句
可以简化条件语句的表达式,使代码更加清晰明了。例如:
```
if (m_bZoomViaProtocol || (pPtzOperationCmd->cmd != PTZ_OPT_ZOOM_WIDE && pPtzOperationCmd->cmd != PTZ_OPT_ZOOM_TELE)) {
ret = sendMsg(msgInfo(SID_GENERALMOVE_STOPCONTINUOUSMOVE, pPtzOperationCmd, PTZ_STOP));
}
```
这样,便可以避免代码冗余,使代码更加简洁易读。
阅读全文