Skip to content

Commit e5f3ce9

Browse files
committed
Refactor(entity_base): Find the target entity status only once
Signed-off-by: Mateusz Palczuk <[email protected]>
1 parent f66fd5b commit e5f3ce9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

simulation/traffic_simulator/src/entity/entity_base.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,15 +774,16 @@ auto EntityBase::requestSynchronize(
774774
RoutingConfiguration lane_changeable_routing_configuration;
775775
lane_changeable_routing_configuration.allow_lane_change = true;
776776

777-
if (other_status_.find(target_name) == other_status_.end()) {
777+
if (const auto target_entity_status_it = other_status_.find(target_name);
778+
target_entity_status_it == other_status_.end()) {
778779
THROW_SEMANTIC_ERROR(
779780
"requestSynchronize(): Entity ", std::quoted(target_name), " does not exist.");
780781
} else if (const auto canonicalized_lanelet_pose = getCanonicalizedLaneletPose();
781782
!canonicalized_lanelet_pose.has_value()) {
782783
THROW_SEMANTIC_ERROR(
783784
"requestSynchronize(): Failed to get lanelet pose of the entity: ", std::quoted(name));
784785
} else if (const auto target_entity_canonicalized_lanelet_pose =
785-
other_status_.find(target_name)->second.getCanonicalizedLaneletPose();
786+
target_entity_status_it->second.getCanonicalizedLaneletPose();
786787
!target_entity_canonicalized_lanelet_pose.has_value()) {
787788
THROW_SEMANTIC_ERROR(
788789
"requestSynchronize(): Failed to get lanelet pose of the target entity: ",
@@ -809,8 +810,7 @@ auto EntityBase::requestSynchronize(
809810
<< std::quoted(target_name) << " has already passed the target lanelet.");
810811
return true;
811812
} else {
812-
const auto target_entity_velocity =
813-
other_status_.find(target_name)->second.getTwist().linear.x;
813+
const auto target_entity_velocity = target_entity_status_it->second.getTwist().linear.x;
814814
const auto entity_velocity = getCurrentTwist().linear.x;
815815
const auto target_entity_arrival_time =
816816
(std::abs(target_entity_velocity) > std::numeric_limits<double>::epsilon())

0 commit comments

Comments
 (0)