r24690 by jghali - #16604: Slow name checks in item creation <fsimonis>

scribus-commit scribus-commit at lists.scribus.net
Tue Aug 10 23:58:08 UTC 2021


Author: jghali
Date: Tue Aug 10 23:58:08 2021
New Revision: 24690

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24690
Log:
#16604: Slow name checks in item creation <fsimonis>

Modified:
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24690&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Tue Aug 10 23:58:08 2021
@@ -6432,28 +6432,34 @@
 }
 
 
-bool ScribusDoc::itemNameExists(const QString& checkItemName)
-{
-	bool found = false;
-	QList<PageItem*> allItems;
-	int docItemCount = Items->count();
-	for (int i = 0; i < docItemCount; ++i)
-	{
-		PageItem *currItem = Items->at(i);
-		if (checkItemName == currItem->itemName())
+bool ScribusDoc::itemNameExists(const QString& checkItemName) const
+{
+	std::vector<PageItem*> groups;
+	groups.reserve(32);
+
+	// Process root elements of the doc and remember groups
+	for (PageItem* item: *Items)
+	{
+		if (item->itemName() == checkItemName)
 			return true;
-		if (currItem->isGroup())
-		{
-			allItems = currItem->getAllChildren();
-			for (int ii = 0; ii < allItems.count(); ii++)
-			{
-				if (checkItemName == allItems.at(ii)->itemName())
-					return true;
-			}
-		}
-		allItems.clear();
-	}
-	return found;
+		if (item->isGroup())
+			groups.push_back(item);
+	}
+
+	// Process groups
+	while (!groups.empty())
+	{
+		PageItem* item = groups.back();
+		groups.pop_back();
+		for (PageItem* item: item->groupItemList)
+		{
+			if (item->itemName() == checkItemName)
+				return true;
+			if (item->isGroup())
+				groups.push_back(item);
+		}
+	}
+	return false;
 }
 
 

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24690&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Tue Aug 10 23:58:08 2021
@@ -960,7 +960,7 @@
 	 * @author Craig Ringer
 	 ** CB Moved from PageItem
 	 */
-	bool itemNameExists(const QString& itemName);
+	bool itemNameExists(const QString& itemName) const;
 	
 	/**
 	 * @brief Set the doc into Master page mode




More information about the scribus-commit mailing list