@@ -133,16 +133,20 @@ int Block::findInput(const std::string &inputName) const
133133 return -1 ;
134134}
135135
136- /* ! Returns the index of the input with the given ID. */
137- int Block::findInputById (int id)
136+ /* ! Returns the input with the given ID. */
137+ Input * Block::findInputById (int id) const
138138{
139- int i = 0 ;
140- for (auto input : m_inputs) {
141- if (input->inputId () == id)
142- return i;
143- i++;
144- }
145- return -1 ;
139+ if (m_inputMap.count (id) == 1 )
140+ return m_inputMap.at (id);
141+ return nullptr ;
142+ }
143+
144+ /* ! Updates the map that assigns input IDs to input indexes. Used internally by Engine. */
145+ void Block::updateInputMap ()
146+ {
147+ m_inputMap.clear ();
148+ for (auto input : m_inputs)
149+ m_inputMap[input->inputId ()] = input.get ();
146150}
147151
148152/* ! Returns the list of fields. */
@@ -177,15 +181,19 @@ int Block::findField(const std::string &fieldName) const
177181}
178182
179183/* ! Returns the index of the field with the given ID. */
180- int Block::findFieldById (int id) const
184+ Field * Block::findFieldById (int id) const
181185{
182- int i = 0 ;
183- for (auto field : m_fields) {
184- if (field->fieldId () == id)
185- return i;
186- i++;
187- }
188- return -1 ;
186+ if (m_fieldMap.count (id) == 1 )
187+ return m_fieldMap.at (id);
188+ return nullptr ;
189+ }
190+
191+ /* ! Updates the map that assigns input IDs to input indexes. Used internally by Engine. */
192+ void Block::updateFieldMap ()
193+ {
194+ m_fieldMap.clear ();
195+ for (auto field : m_fields)
196+ m_fieldMap[field->fieldId ()] = field.get ();
189197}
190198
191199/* ! Returns true if this is a shadow block. */
0 commit comments