From f9aed763e4e2f5b9851a1c218fc620c00d95a2e6 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 27 Sep 2020 10:16:43 +0800 Subject: [PATCH] App: fix recursive App::getLinksTo() --- src/App/Application.h | 2 +- src/App/Document.cpp | 20 ++++++++++++-------- src/App/Document.h | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/App/Application.h b/src/App/Application.h index eccf6962cb..2d0fa041a7 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -398,7 +398,7 @@ public: /** Return the links to a given object * * @param obj: the linked object. If NULL, then all links are returned. - * @param option: @sa App::GetLinkOptions + * @param option: @sa App::GetLinkOption * @param maxCount: limit the number of links returned, 0 means no limit */ std::set getLinksTo( diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 64d0cc8aca..7a7822238a 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2943,7 +2943,7 @@ void Document::getLinksTo(std::set &links, const DocumentObject *obj, int options, int maxCount, const std::vector &objs) const { - std::map linkMap; + std::map > linkMap; for(auto o : objs.size()?objs:d->objectArray) { if(o == obj) continue; @@ -2960,7 +2960,7 @@ void Document::getLinksTo(std::set &links, if(linked && linked!=o) { if(options & GetLinkRecursive) - linkMap[linked] = o; + linkMap[linked].push_back(o); else if(linked == obj || !obj) { if((options & GetLinkExternal) && linked->getDocument()==o->getDocument()) @@ -2983,15 +2983,19 @@ void Document::getLinksTo(std::set &links, if(!GetApplication().checkLinkDepth(depth,true)) break; std::vector next; - for(auto o : current) { + for(const App::DocumentObject *o : current) { auto iter = linkMap.find(o); - if(iter!=linkMap.end() && links.insert(iter->second).second) { - if(maxCount && maxCount<=(int)links.size()) - return; - next.push_back(iter->second); + if(iter==linkMap.end()) + continue; + for (App::DocumentObject *link : iter->second) { + if (links.insert(link).second) { + if(maxCount && maxCount<=(int)links.size()) + return; + next.push_back(link); + } } } - current.swap(next); + current = std::move(next); } return; } diff --git a/src/App/Document.h b/src/App/Document.h index 24f91f7a68..4b5e727c4a 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -477,7 +477,7 @@ public: * * @param links: holds the links found * @param obj: the linked object. If NULL, then all links are returned. - * @param option: @sa App::GetLinkOptions + * @param option: @sa App::GetLinkOption * @param maxCount: limit the number of links returned, 0 means no limit * @param objs: optional objects to search for, if empty, then all objects * of this document are searched.