From 55f7f723a0dd489a931b8109e871a8aeda971c93 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 11 Aug 2023 02:13:45 -0400 Subject: [PATCH] ui onroad: utilize local variables for repeated capnp reader access (#29325) old-commit-hash: 22cf5421d625aaf578efcf572404a4d096c269b8 --- selfdrive/ui/qt/onroad.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 59868fb225..7c070d2adf 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -270,6 +270,8 @@ void AnnotatedCameraWidget::updateState(const UIState &s) { const bool nav_alive = sm.alive("navInstruction") && sm["navInstruction"].getValid(); const auto cs = sm["controlsState"].getControlsState(); + const auto car_state = sm["carState"].getCarState(); + const auto nav_instruction = sm["navInstruction"].getNavInstruction(); // Handle older routes where vCruiseCluster is not set float v_cruise = cs.getVCruiseCluster() == 0.0 ? cs.getVCruise() : cs.getVCruiseCluster(); @@ -281,17 +283,17 @@ void AnnotatedCameraWidget::updateState(const UIState &s) { // Handle older routes where vEgoCluster is not set float v_ego; - if (sm["carState"].getCarState().getVEgoCluster() == 0.0 && !v_ego_cluster_seen) { - v_ego = sm["carState"].getCarState().getVEgo(); + if (car_state.getVEgoCluster() == 0.0 && !v_ego_cluster_seen) { + v_ego = car_state.getVEgo(); } else { - v_ego = sm["carState"].getCarState().getVEgoCluster(); + v_ego = car_state.getVEgoCluster(); v_ego_cluster_seen = true; } float cur_speed = cs_alive ? std::max(0.0, v_ego) : 0.0; cur_speed *= s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH; - auto speed_limit_sign = sm["navInstruction"].getNavInstruction().getSpeedLimitSign(); - float speed_limit = nav_alive ? sm["navInstruction"].getNavInstruction().getSpeedLimit() : 0.0; + auto speed_limit_sign = nav_instruction.getSpeedLimitSign(); + float speed_limit = nav_alive ? nav_instruction.getSpeedLimit() : 0.0; speed_limit *= (s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH); setProperty("speedLimit", speed_limit);