Skip to content

Commit c5bfcde

Browse files
committed
Block: Do not add existing inputs and fields
1 parent 2c7eb8a commit c5bfcde

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/scratch/block.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ std::vector<std::shared_ptr<Input>> Block::inputs() const
126126
/*! Adds an input and returns its index. */
127127
int Block::addInput(std::shared_ptr<Input> input)
128128
{
129+
auto it = std::find(impl->inputs.begin(), impl->inputs.end(), input);
130+
131+
if (it != impl->inputs.end())
132+
return it - impl->inputs.begin();
133+
129134
impl->inputs.push_back(input);
130135
return impl->inputs.size() - 1;
131136
}
@@ -173,6 +178,11 @@ std::vector<std::shared_ptr<Field>> Block::fields() const
173178
/*! Adds a field and returns its index. */
174179
int Block::addField(std::shared_ptr<Field> field)
175180
{
181+
auto it = std::find(impl->fields.begin(), impl->fields.end(), field);
182+
183+
if (it != impl->fields.end())
184+
return it - impl->fields.begin();
185+
176186
impl->fields.push_back(field);
177187
return impl->fields.size() - 1;
178188
}

0 commit comments

Comments
 (0)