r25068 by craig - Code cleanup, in particular recude QString allocations by misuse of

scribus-commit scribus-commit at lists.scribus.net
Mon Mar 28 19:46:39 UTC 2022


Author: craig
Date: Mon Mar 28 19:46:39 2022
New Revision: 25068

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=25068
Log:
Code cleanup, in particular recude QString allocations by misuse of
QString::replace

Modified:
    trunk/Scribus/scribus/canvasmode_nodeedit.cpp
    trunk/Scribus/scribus/fonts/ftface.cpp
    trunk/Scribus/scribus/fpointarray.cpp
    trunk/Scribus/scribus/pdflib_core.cpp
    trunk/Scribus/scribus/pdfwriter.cpp
    trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp
    trunk/Scribus/scribus/plugins/gettext/textfilter/textfilter.cpp
    trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
    trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
    trunk/Scribus/scribus/plugins/import/shape/importshape.cpp
    trunk/Scribus/scribus/plugins/short-words/parse.cpp
    trunk/Scribus/scribus/scpaths.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/ui/aboutplugins.cpp
    trunk/Scribus/scribus/ui/aboutplugins.h
    trunk/Scribus/scribus/ui/aligndistribute.cpp
    trunk/Scribus/scribus/ui/effectsdialog.cpp
    trunk/Scribus/scribus/ui/hyask.cpp
    trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp

Modified: trunk/Scribus/scribus/canvasmode_nodeedit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/canvasmode_nodeedit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_nodeedit.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_nodeedit.cpp	Mon Mar 28 19:46:39 2022
@@ -919,16 +919,15 @@
 	if (edited)
 	{
 		currItem->FrameType = 3;
-		double xp, yp, w, h, xp2, yp2, w2, h2;
-		xp = currItem->xPos();
-		yp = currItem->yPos();
-		w = currItem->width();
-		h = currItem->height();
+		double xp = currItem->xPos();
+		double yp = currItem->yPos();
+		double w = currItem->width();
+		double h = currItem->height();
 		m_doc->adjustItemSize(currItem, true);
-		xp2 = currItem->xPos();
-		yp2 = currItem->yPos();
-		w2 = currItem->width();
-		h2 = currItem->height();
+		double xp2 = currItem->xPos();
+		double yp2 = currItem->yPos();
+		double w2 = currItem->width();
+		double h2 = currItem->height();
 		currItem->update();
 		if ((xp != xp2) || (yp != yp2) || (w != w2) || (h != h2))
 			m_view->DrawNew();

Modified: trunk/Scribus/scribus/fonts/ftface.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/fonts/ftface.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/ftface.cpp	(original)
+++ trunk/Scribus/scribus/fonts/ftface.cpp	Mon Mar 28 19:46:39 2022
@@ -82,7 +82,8 @@
 {
 	ScFaceData::load();
 
-	if (!m_face) {
+	if (!m_face)
+	{
 		if (FT_New_Face( m_library, QFile::encodeName(fontFile), faceIndex, & m_face ))
 		{
 			status = ScFace::BROKEN;
@@ -160,15 +161,15 @@
 			const_cast<FtFace*>(this)->isStroked = true;
 		charcode = FT_Get_Next_Char( m_face, charcode, &gindex );
 	}
-	if (invalidGlyph > 0) {
+	if (invalidGlyph > 0)
 		status = ScFace::BROKENGLYPHS;
-	}
 }
 
 
 void FtFace::unload() const
 {
-	if (m_face) {
+	if (m_face)
+	{
 		FT_Done_Face( m_face );
 		m_face = nullptr;
 	}

Modified: trunk/Scribus/scribus/fpointarray.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/fpointarray.cpp
==============================================================================
--- trunk/Scribus/scribus/fpointarray.cpp	(original)
+++ trunk/Scribus/scribus/fpointarray.cpp	Mon Mar 28 19:46:39 2022
@@ -900,8 +900,8 @@
 
 bool FPointArray::parseSVG(const QString& svgPath)
 {
-	QString d = svgPath;
-	d = d.replace(QRegularExpression(","), " ");
+	QString d(svgPath);
+	d.replace(QRegularExpression(","), " ");
 
 	bool ret = false;
 	if (d.isEmpty())

Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Mon Mar 28 19:46:39 2022
@@ -2316,9 +2316,9 @@
 
 void PDFLibCore::PDF_Begin_WriteUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, QString> >& usedFonts)
 {
-	qDebug() << "embed list:" << QStringList(Options.EmbedList).join(", ");
-	qDebug() << "subset list:" << QStringList(Options.SubsetList).join(", ");
-	qDebug() << "outline list:" << QStringList(Options.OutlineList).join(", ");
+//	qDebug() << "embed list:" << QStringList(Options.EmbedList).join(", ");
+//	qDebug() << "subset list:" << QStringList(Options.SubsetList).join(", ");
+//	qDebug() << "outline list:" << QStringList(Options.OutlineList).join(", ");
 
 	int a = 0;
 	for (auto it = usedFonts.cbegin(); it != usedFonts.cend(); ++it)

Modified: trunk/Scribus/scribus/pdfwriter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/pdfwriter.cpp
==============================================================================
--- trunk/Scribus/scribus/pdfwriter.cpp	(original)
+++ trunk/Scribus/scribus/pdfwriter.cpp	Mon Mar 28 19:46:39 2022
@@ -460,8 +460,8 @@
 	
 	QByteArray toDateString(const QDateTime& dt)
 	{
-		QString tmp = dt.toString("yyyy:MM:dd:HH:mm:ss");
-		tmp = tmp.replace(":", "");
+		QString tmp(dt.toString("yyyy:MM:dd:HH:mm:ss"));
+		tmp.replace(":", "");
 		return "D:" + tmp.toLatin1() + "Z";
 	}
 	

Modified: trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp	(original)
+++ trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp	Mon Mar 28 19:46:39 2022
@@ -168,7 +168,7 @@
 
 bool ContentReader::characters(const QString &ch) 
 {
-	QString tmp = ch;
+	QString tmp(ch);
 	tmp = tmp.remove("\n");
 	tmp = tmp.remove(""); // Remove all OO.o hyphenation chars
 	// Unneeded as scribus now also use standard unicode non-breakable space

Modified: trunk/Scribus/scribus/plugins/gettext/textfilter/textfilter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/plugins/gettext/textfilter/textfilter.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/textfilter/textfilter.cpp	(original)
+++ trunk/Scribus/scribus/plugins/gettext/textfilter/textfilter.cpp	Mon Mar 28 19:46:39 2022
@@ -112,9 +112,9 @@
 					break;
 				case REPLACE:
 					if (useRegexp)
-						text = text.replace(rx, replaceWith); 
+						text.replace(rx, replaceWith);
 					else
-						text = text.replace(regExp, replaceWith);
+						text.replace(regExp, replaceWith);
 					break;
 				case APPLY: 
 					pstyles[pstyle] = new gtParagraphStyle(*fstyle);

Modified: trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/odg/importodg.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/odg/importodg.cpp	Mon Mar 28 19:46:39 2022
@@ -2854,7 +2854,7 @@
 bool OdgPlug::parseEnhPath(const QString& svgPath, FPointArray &result, bool &fill, bool &stroke)
 {
 	QString d(svgPath);
-	d = d.replace( QRegularExpression( "," ), " ");
+	d.replace( QRegularExpression( "," ), " ");
 	bool ret = false;
 	fill = true;
 	stroke = true;

Modified: trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp	Mon Mar 28 19:46:39 2022
@@ -1571,7 +1571,7 @@
 bool OODPlug::parseSVG(const QString &s, FPointArray *ite)
 {
 	QString d(s);
-	d = d.replace( QRegularExpression( "," ), " ");
+	d.replace( QRegularExpression( "," ), " ");
 	bool ret = false;
 	if (!d.isEmpty())
 	{

Modified: trunk/Scribus/scribus/plugins/import/shape/importshape.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/plugins/import/shape/importshape.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/shape/importshape.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/shape/importshape.cpp	Mon Mar 28 19:46:39 2022
@@ -860,16 +860,12 @@
 
 const char * ShapePlug::getCoord( const char *ptr, double &number )
 {
-	int integer, exponent;
-	double decimal, frac;
-	int sign, expsign;
-
-	exponent = 0;
-	integer = 0;
-	frac = 1.0;
-	decimal = 0;
-	sign = 1;
-	expsign = 1;
+	int exponent = 0;
+	int integer = 0;
+	double frac = 1.0;
+	double decimal = 0.0;
+	int sign = 1;
+	int expsign = 1;
 
 	// read the sign
 	if (*ptr == '+')
@@ -922,8 +918,8 @@
 
 bool ShapePlug::parseSVG( const QString &s, FPointArray *ite )
 {
-	QString d = s;
-	d = d.replace( QRegularExpression( "," ), " ");
+	QString d(s);
+	d.replace( QRegularExpression( "," ), " ");
 	bool ret = false;
 	if (!d.isEmpty())
 	{

Modified: trunk/Scribus/scribus/plugins/short-words/parse.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/plugins/short-words/parse.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/short-words/parse.cpp	(original)
+++ trunk/Scribus/scribus/plugins/short-words/parse.cpp	Mon Mar 28 19:46:39 2022
@@ -82,7 +82,7 @@
 	{
 		unbreak = (*it);
 		// replace ' ' from cfg with '~' in the replacement string
-		unbreak = unbreak.replace(SPACE, SpecialChars::NBSPACE);
+		unbreak.replace(SPACE, SpecialChars::NBSPACE);
 		/*
 		Regexp used to find the config string (*it) in content.
 		Cheat sheet:

Modified: trunk/Scribus/scribus/scpaths.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/scpaths.cpp
==============================================================================
--- trunk/Scribus/scribus/scpaths.cpp	(original)
+++ trunk/Scribus/scribus/scpaths.cpp	Mon Mar 28 19:46:39 2022
@@ -438,8 +438,8 @@
 	osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed
 	GetVersionEx(&osVersion);  // Get Windows version infos
 	GetSystemDirectoryW(sysDir, MAX_PATH); // windowsSpecialDir(CSIDL_SYSTEM) fails on Win9x
-	QString winSysDir = QString::fromUtf16((const ushort*) sysDir);
-	winSysDir = winSysDir.replace('\\','/');
+	QString winSysDir(QString::fromUtf16((const ushort*) sysDir));
+	winSysDir.replace('\\','/');
 	if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) // Windows NT/2k/XP
 	{
 		if (osVersion.dwMajorVersion >= 5) // for 2k and XP dwMajorVersion == 5 

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Mon Mar 28 19:46:39 2022
@@ -4746,9 +4746,9 @@
 		else
 		{
 			// K.I.S.S.:
-			QString text = QApplication::clipboard()->text(QClipboard::Clipboard);
-			text = text.replace("\r\n", SpecialChars::PARSEP);
-			text = text.replace('\n', SpecialChars::PARSEP);
+			QString text (QApplication::clipboard()->text(QClipboard::Clipboard));
+			text.replace("\r\n", SpecialChars::PARSEP);
+			text.replace('\n', SpecialChars::PARSEP);
 			if (UndoManager::undoEnabled())
 			{
 				SimpleState *is = new SimpleState(Um::Paste, QString(), Um::IPaste);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Mon Mar 28 19:46:39 2022
@@ -17480,7 +17480,7 @@
 		if (note->noteMark() != nullptr)
 		{
 			note->noteMark()->setString(numStr);
-			label = label.replace("NoteMark","NoteFrameMark");
+			label.replace("NoteMark","NoteFrameMark");
 			note->noteMark()->label = label;
 		}
 		++index;

Modified: trunk/Scribus/scribus/ui/aboutplugins.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/ui/aboutplugins.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/aboutplugins.cpp	(original)
+++ trunk/Scribus/scribus/ui/aboutplugins.cpp	Mon Mar 28 19:46:39 2022
@@ -91,9 +91,10 @@
 	plugin->deleteAboutData(about);
 }
 
-QString AboutPlugins::htmlize(QString s)
+QString AboutPlugins::htmlize(const QString& s)
 {
-	QString ret = s.replace('<', "<");
-	ret = ret.replace('>', ">");
+	QString ret(s);
+	ret.replace('<', "<");
+	ret.replace('>', ">");
 	return ret;
 }

Modified: trunk/Scribus/scribus/ui/aboutplugins.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/ui/aboutplugins.h
==============================================================================
--- trunk/Scribus/scribus/ui/aboutplugins.h	(original)
+++ trunk/Scribus/scribus/ui/aboutplugins.h	Mon Mar 28 19:46:39 2022
@@ -35,7 +35,7 @@
 		\param s string to process
 		\retval QString a string with changed lt/gt
 		*/
-		QString htmlize(QString s);
+		QString htmlize(const QString &s);
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/aligndistribute.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/ui/aligndistribute.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/aligndistribute.cpp	(original)
+++ trunk/Scribus/scribus/ui/aligndistribute.cpp	Mon Mar 28 19:46:39 2022
@@ -223,12 +223,11 @@
 
 void AlignDistributePalette::unitChange()
 {
-	if (currDoc != nullptr)
-	{
-		unitRatio = unitGetRatioFromIndex(currDoc->unitIndex());
-		distributeDistSpinBox->setNewUnit(currDoc->unitIndex());
-		enableGuideButtons();
-	}
+	if (currDoc == nullptr)
+		return;
+	unitRatio = unitGetRatioFromIndex(currDoc->unitIndex());
+	distributeDistSpinBox->setNewUnit(currDoc->unitIndex());
+	enableGuideButtons();
 }
 
 void AlignDistributePalette::setDoc(ScribusDoc* newDoc)
@@ -357,7 +356,6 @@
 	if (currDoc != nullptr)
 		currDoc->itemSelection_DistributeDownPage(true);
 }
-
 
 void AlignDistributePalette::distributeBottom()
 {
@@ -451,18 +449,12 @@
 		case 0:
 			guideInfoText = tr("Y: %1%2").arg(guidePosition * unitRatio, 0, 'f', precision).arg(suffix);
 			if (currAlignTo == ScribusDoc::alignGuide)
-			{
 				setterV = false;
-				setterH = true;
-			}
 			break;
 		case 1:
 			guideInfoText = tr("X: %1%2").arg(guidePosition * unitRatio, 0, 'f', precision).arg(suffix);
 			if (currAlignTo == ScribusDoc::alignGuide)
-			{
-				setterV = true;
 				setterH = false;
-			}
 			break;
 	}
 	bool setterO = true;
@@ -472,7 +464,7 @@
 	alignLeftInToolButton->setEnabled(setterV);
 	alignLeftOutToolButton->setEnabled(setterO);
 	alignRightInToolButton->setEnabled(setterV);
-	alignRightOutToolButton->setEnabled(setterO);	
+	alignRightOutToolButton->setEnabled(setterO);
 	alignCenterHorToolButton->setEnabled(setterV);
 
 	alignTopInToolButton->setEnabled(setterH);

Modified: trunk/Scribus/scribus/ui/effectsdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/ui/effectsdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/effectsdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/effectsdialog.cpp	Mon Mar 28 19:46:39 2022
@@ -1433,7 +1433,7 @@
 		}
 		if (currentOptions->text() == tr("Tritone"))
 		{
-			QString efval = "";
+			QString efval;
 			efval = colDatat1->currentText()+"\n";
 			efval += colDatat2->currentText()+"\n";
 			efval += colDatat3->currentText()+"\n";

Modified: trunk/Scribus/scribus/ui/hyask.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/ui/hyask.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/hyask.cpp	(original)
+++ trunk/Scribus/scribus/ui/hyask.cpp	Mon Mar 28 19:46:39 2022
@@ -142,9 +142,9 @@
 void HyAsk::Check()
 {
 	disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
-	QString in = Wort->text();
-	QString out = in.replace ( QRegularExpression ( "(-)+" ), "-" );
-	Wort->setText ( out );
+	QString newText(Wort->text());
+	newText.replace ( QRegularExpression ( "(-)+" ), "-" );
+	Wort->setText(newText);
 	addToExceptionList->setEnabled(true);
 	addToExceptionListText->setEnabled(true);
 	connect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
@@ -153,9 +153,9 @@
 void HyAsk::DoSkip()
 {
 	disconnect ( Wort, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( Check() ) );
-	QString in = Wort->text();
-	QString out = in.replace ( QRegularExpression ( "(-)+" ), "" );
-	Wort->setText ( out );
+	QString newText(Wort->text());
+	newText.replace ( QRegularExpression ( "(-)+" ), "" );
+	Wort->setText(newText);
 	accept();
 }
 

Modified: trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25068&path=/trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp	(original)
+++ trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp	Mon Mar 28 19:46:39 2022
@@ -1264,14 +1264,12 @@
 	setWindowTitle( tr("Properties"));
 	retranslateUi(this);
 
-	QString ptSuffix = tr(" pt");
-
-	QString ein = (m_haveDoc) ? unitGetSuffixFromIndex(m_doc->unitIndex()) : ptSuffix;
-
-	xposSpin->setSuffix(ein);
-	yposSpin->setSuffix(ein);
-	widthSpin->setSuffix(ein);
-	heightSpin->setSuffix(ein);
+	QString suffix = m_haveDoc ? unitGetSuffixFromIndex(m_doc->unitIndex()) : tr(" pt");
+
+	xposSpin->setSuffix(suffix);
+	yposSpin->setSuffix(suffix);
+	widthSpin->setSuffix(suffix);
+	heightSpin->setSuffix(suffix);
 }
 
 void PropertiesPalette_XYZ::updateSpinBoxConstants()




More information about the scribus-commit mailing list