diff --git a/include/core/state_block/has_state_blocks.h b/include/core/state_block/has_state_blocks.h index ac82297f5e36b5130151bd1b0464a110264b5fe7..95e2f83f5b5f8fbc5de876b9457a4b0ead0ac1bc 100644 --- a/include/core/state_block/has_state_blocks.h +++ b/include/core/state_block/has_state_blocks.h @@ -341,11 +341,7 @@ inline void HasStateBlocks::setState(const StateStructure& _structure, const std //// _structure can be either stateblock structure of the node or a subset of this structure inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) const { - StateStructure structure; - if (_structure == "") - structure = structure_; - else - structure = _structure; + const StateStructure& structure = (_structure == "" ? structure_ : _structure); VectorXd state(getSize(structure)); @@ -370,11 +366,11 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure for (const auto key : structure) { - auto state_it = state_block_map_.find(key); + const auto& sb = getStateBlock(key); - if (state_it != state_block_map_.end()) + assert(sb != nullptr && "Requested StateBlock key not in the structure"); - state.emplace(key, state_it->second->getState()); + state.emplace(key, sb->getState()); } return state;