Skip to content

Commit eba73d6

Browse files
Optimize itemAt to avoid redundant select() calls
Refactored to use recursiveDo instead of findAny twice, eliminating the duplicate call to select(x,y) on the same group. Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
1 parent 5513afb commit eba73d6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

model/canvas.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,21 @@ namespace minsky
428428
if (!item)
429429
{
430430
// Check if clicking on a group's edge I/O variable
431-
if (auto g=model->findAny
431+
model->recursiveDo(&Group::groups,
432+
[&](Groups&, Groups::const_iterator i)
433+
{
434+
if ((*i)->visible())
435+
if (auto selected=(*i)->select(x,y))
436+
{
437+
item=selected;
438+
return true;
439+
}
440+
return false;
441+
});
442+
if (!item)
443+
item=model->findAny
432444
(&Group::groups, [&](const GroupPtr& i)
433-
{return i->visible() && i->select(x,y);}))
434-
if (auto selected=g->select(x,y))
435-
return selected;
436-
item=model->findAny
437-
(&Group::groups, [&](const GroupPtr& i)
438-
{return i->visible() && i->clickType(x,y)!=ClickType::outside;});
445+
{return i->visible() && i->clickType(x,y)!=ClickType::outside;});
439446
}
440447
return item;
441448
}

0 commit comments

Comments
 (0)