r23853 by jghali - Improve performance of scripter's getAllText() and getFrameText()

scribus-commit scribus-commit at lists.scribus.net
Fri May 29 19:08:01 UTC 2020


Author: jghali
Date: Fri May 29 19:08:01 2020
New Revision: 23853

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23853
Log:
Improve performance of scripter's getAllText() and getFrameText()

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
    trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdtext.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23853&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	Fri May 29 19:08:01 2020
@@ -314,7 +314,6 @@
 		return nullptr;
 	if (!checkHaveDocument())
 		return nullptr;
-	QString text = "";
 	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
 	if (item == nullptr)
 		return nullptr;
@@ -323,16 +322,20 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
+	
+	const StoryText& story = item->itemText;
+	QString text;
+	text.reserve(story.isSelected() ? story.selectionLength() : story.length());
 	for (int i = item->firstInFrame(); i <= item->lastInFrame(); ++i)
 	{
 		if (item->HasSel)
 		{
-			if (item->itemText.selected(i))
-				text += item->itemText.text(i);
+			if (story.selected(i))
+				text += story.text(i);
 		}
 		else
 		{
-			text += item->itemText.text(i);
+			text += story.text(i);
 		}
 	}
 	return PyUnicode_FromString(text.toUtf8());
@@ -345,7 +348,6 @@
 		return nullptr;
 	if (!checkHaveDocument())
 		return nullptr;
-	QString text = "";
 	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
 	if (item == nullptr)
 		return nullptr;
@@ -356,18 +358,21 @@
 	}
 
 	// collect all chars from a storytext
-	for (int i = 0; i < item->itemText.length(); i++)
+	const StoryText& story = item->itemText;
+	QString text;
+	text.reserve(story.isSelected() ? story.selectionLength() : story.length());
+	for (int i = 0; i < story.length(); i++)
 	{
 		if (item->HasSel)
 		{
-			if (item->itemText.selected(i))
-				text += item->itemText.text(i);
+			if (story.selected(i))
+				text += story.text(i);
 		}
 		else
 		{
-			text += item->itemText.text(i);
+			text += story.text(i);
 		}
-	} // for
+	}
 	return PyUnicode_FromString(text.toUtf8());
 }
 

Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23853&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdtext.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdtext.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdtext.cpp	Fri May 29 19:08:01 2020
@@ -314,7 +314,6 @@
 		return nullptr;
 	if (!checkHaveDocument())
 		return nullptr;
-	QString text = "";
 	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
 	if (item == nullptr)
 		return nullptr;
@@ -323,16 +322,20 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
+	
+	const StoryText& story = item->itemText;
+	QString text;
+	text.reserve(story.isSelected() ? story.selectionLength() : story.length());
 	for (int i = item->firstInFrame(); i <= item->lastInFrame(); ++i)
 	{
 		if (item->HasSel)
 		{
-			if (item->itemText.selected(i))
-				text += item->itemText.text(i);
+			if (story.selected(i))
+				text += story.text(i);
 		}
 		else
 		{
-			text += item->itemText.text(i);
+			text += story.text(i);
 		}
 	}
 	return PyString_FromString(text.toUtf8());
@@ -345,7 +348,6 @@
 		return nullptr;
 	if (!checkHaveDocument())
 		return nullptr;
-	QString text = "";
 	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
 	if (item == nullptr)
 		return nullptr;
@@ -356,18 +358,21 @@
 	}
 
 	// collect all chars from a storytext
-	for (int i = 0; i < item->itemText.length(); i++)
+	const StoryText& story = item->itemText;
+	QString text;
+	text.reserve(story.isSelected() ? story.selectionLength() : story.length());
+	for (int i = 0; i < story.length(); i++)
 	{
 		if (item->HasSel)
 		{
-			if (item->itemText.selected(i))
-				text += item->itemText.text(i);
+			if (story.selected(i))
+				text += story.text(i);
 		}
 		else
 		{
-			text += item->itemText.text(i);
+			text += story.text(i);
 		}
-	} // for
+	}
 	return PyString_FromString(text.toUtf8());
 }
 




More information about the scribus-commit mailing list