r24185 by craig - Optimise some container appends by reserving allocations. Clean up some

scribus-commit scribus-commit at lists.scribus.net
Fri Nov 6 00:03:19 UTC 2020


Author: craig
Date: Fri Nov  6 00:03:19 2020
New Revision: 24185

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24185
Log:
Optimise some container appends by reserving allocations. Clean up some
variable naming.

Modified:
    trunk/Scribus/scribus/fonts/cff.cpp
    trunk/Scribus/scribus/fonts/sfnt.cpp
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_pict.cpp
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_psd.cpp
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_wpg.cpp
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem_group.cpp
    trunk/Scribus/scribus/pageitem_table.cpp
    trunk/Scribus/scribus/palettes/cxfmeasurementspec.cpp
    trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
    trunk/Scribus/scribus/plugins/import/svm/importsvm.cpp
    trunk/Scribus/scribus/plugins/import/xfig/importxfig.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/customfdialog.cpp
    trunk/Scribus/scribus/ui/prefs_tableofcontents.cpp
    trunk/Scribus/scribus/ui/printdialog.cpp
    trunk/Scribus/scribus/util_math.cpp

Modified: trunk/Scribus/scribus/fonts/cff.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/fonts/cff.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/cff.cpp	(original)
+++ trunk/Scribus/scribus/fonts/cff.cpp	Fri Nov  6 00:03:19 2020
@@ -823,6 +823,7 @@
 			start = start << 8 | (uchar) m_bytes[pos++];
 		}
 		start += dataStart;
+		result.reserve(N);
 		for (uint i = 0; i < N; ++i)
 		{
 			end = 0;
@@ -843,6 +844,7 @@
 	QList<uint> CFF::readEncoding(uint& pos) const
 	{
 		QList<uint> result;
+		result.reserve(256);
 		for(int i = 0; i < 256; ++i)
 			result.append(0);
 		
@@ -1650,8 +1652,10 @@
 			QList<sid_type> newCharset;
 			// new charStrings
 			QList<QByteArray> newCharStrings;
-
-			for (int i = 0; i < cids.length(); ++i)
+			int cidsLength = cids.length();
+			newCharset.reserve(cidsLength);
+			newCharStrings.reserve(cidsLength);
+			for (int i = 0; i < cidsLength; ++i)
 			{
 				sid_type gid = cids[i];
 				sid_type sid = charset[gid];

Modified: trunk/Scribus/scribus/fonts/sfnt.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/fonts/sfnt.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/sfnt.cpp	(original)
+++ trunk/Scribus/scribus/fonts/sfnt.cpp	Fri Nov  6 00:03:19 2020
@@ -600,19 +600,16 @@
 	{
 		QList<quint32> result;
 		const QByteArray loca = getTable(ttf, "loca");
+		result.reserve(loca.length());
 		if (hasLongLocaFormat(ttf))
 		{
 			for (int i = 0; i < loca.length(); i+=4)
-			{
 				result.append(word(loca, i));
-			}
 		}
 		else
 		{
 			for (int i = 0; i < loca.length(); i+=2)
-			{
 				result.append(word16(loca, i) * 2);
-			}
 		}
 		return result;
 	}
@@ -1148,6 +1145,7 @@
 		{
 			QList<std::pair<qint16, quint16> > oldHmtx = readHmtx(ttf);
 			QList<std::pair<qint16, quint16> > newHmtx;
+			newHmtx.reserve(glyphs.length() + 1);
 			newHmtx.append(std::pair<qint16, quint16>(1234, 123));
 			for (int i = 1; i < glyphs.length(); ++i)
 				newHmtx.append(newHmtx[0]);

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_pict.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_pict.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_pict.cpp	(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_pict.cpp	Fri Nov  6 00:03:19 2020
@@ -1323,6 +1323,7 @@
 			ts >> ct_seed;
 			ts >> ct_flags >> ct_size;
 //			qDebug() << "ColorTable has" << ct_size << "Entries";
+			colors.reserve(ct_size+1);
 			for (quint16 cc = 0; cc < ct_size+1; cc++)
 			{
 				quint16 cev, cRed, cGreen, cBlue;

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_psd.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_psd.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_psd.cpp	(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_psd.cpp	Fri Nov  6 00:03:19 2020
@@ -291,7 +291,7 @@
 
 	uint tmp;
 	uint cdataStart;
-	uint ressourceDataLen;
+	uint resourceDataLen;
 //	uint startRessource;
 
 	s.device()->seek( dataOffset );
@@ -460,10 +460,11 @@
 			QList<uchar> colorTableR;
 			QList<uchar> colorTableG;
 			QList<uchar> colorTableB;
-			colorTableR.clear();
-			colorTableG.clear();
-			colorTableB.clear();
+			colorTableR.reserve(256);
+			colorTableG.reserve(256);
+			colorTableB.reserve(256);
 			m_colorTable.clear();
+			m_colorTable.reserve(256);
 			uchar r;
 			for (uint cc = 0; cc < 256; cc++)
 			{
@@ -487,10 +488,10 @@
 		}
 	}
 	s.device()->seek( cdataStart + tmp );
-	s >> ressourceDataLen;
+	s >> resourceDataLen;
 //	startRessource = s.device()->pos();
-	if (ressourceDataLen != 0)
-		parseRessourceData(s, header, ressourceDataLen);
+	if (resourceDataLen != 0)
+		parseRessourceData(s, header, resourceDataLen);
 	return true;
 }
 

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_wpg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_wpg.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_wpg.cpp	(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_wpg.cpp	Fri Nov  6 00:03:19 2020
@@ -62,18 +62,14 @@
 void ScrPainterIm::setPen(const libwpg::WPGPen& pen)
 {
 	QVector<double> dashArray;
-	dashArray.clear();
 	Qt::PenJoinStyle lineJoin;
 	Qt::PenCapStyle lineEnd;
 	double LineW = 72 * pen.width;
 	QColor foreColor = QColor(pen.foreColor.red, pen.foreColor.green, pen.foreColor.blue, 255 - pen.foreColor.alpha);
 	if(!pen.solid)
 	{
-		dashArray.clear();
 		for (unsigned i = 0; i < pen.dashArray.count(); i++)
-		{
 			dashArray.append(pen.dashArray.at(i)*LineW);
-		}
 	}
 	switch (pen.joinstyle)
 	{

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp	(original)
+++ trunk/Scribus/scribus/pageitem.cpp	Fri Nov  6 00:03:19 2020
@@ -2989,6 +2989,7 @@
 	for (int x = 0; x < rows + 1; x++)
 	{
 		QList<MeshPoint> mgList;
+		mgList.reserve(cols + 1);
 		for (int y = 0; y < cols + 1; y++)
 		{
 			MeshPoint mgP;

Modified: trunk/Scribus/scribus/pageitem_group.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/pageitem_group.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_group.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_group.cpp	Fri Nov  6 00:03:19 2020
@@ -73,6 +73,7 @@
 QList<PageItem*> PageItem_Group::getAllChildren() const
 {
 	QList<PageItem*> ret;
+	ret.reserve(groupItemList.count());
 	for (int em = 0; em < groupItemList.count(); ++em)
 	{
 		PageItem* embedded = groupItemList.at(em);

Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_table.cpp	Fri Nov  6 00:03:19 2020
@@ -550,6 +550,7 @@
 
 		// Insert a row of cells.
 		QList<TableCell> cellRow;
+		cellRow.reserve(columns());
 		for (int col = 0; col < columns(); ++col)
 			cellRow.append(TableCell(row, col, this));
 		m_cellRows.insert(row, cellRow);

Modified: trunk/Scribus/scribus/palettes/cxfmeasurementspec.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/palettes/cxfmeasurementspec.cpp
==============================================================================
--- trunk/Scribus/scribus/palettes/cxfmeasurementspec.cpp	(original)
+++ trunk/Scribus/scribus/palettes/cxfmeasurementspec.cpp	Fri Nov  6 00:03:19 2020
@@ -100,7 +100,7 @@
 QVector<int> CxfMeasurementSpec::wavelengths(int start, int increment, int count)
 {
 	QVector<int> wls;
-	
+	wls.reserve(count);
 	int wl = start;
 	for (int i = 0; i < count; ++i)
 	{
@@ -109,4 +109,4 @@
 	}
 	
 	return wls;
-}
+}

Modified: trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pct/importpct.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/pct/importpct.cpp	Fri Nov  6 00:03:19 2020
@@ -1694,6 +1694,7 @@
 			ts >> ct_seed;
 			ts >> ct_flags >> ct_size;
 //			qDebug() << "ColorTable has" << ct_size << "Entries";
+			colors.reserve(ct_size + 1);
 			for (quint16 cc = 0; cc < ct_size+1; cc++)
 			{
 				quint16 cev, cRed, cGreen, cBlue;

Modified: trunk/Scribus/scribus/plugins/import/svm/importsvm.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/plugins/import/svm/importsvm.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/svm/importsvm.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/svm/importsvm.cpp	Fri Nov  6 00:03:19 2020
@@ -1070,11 +1070,13 @@
 				qint64 posC = ds.device()->pos();
 				quint16  numPoints;
 				ds >> numPoints;
+				points.reserve(numPoints);
 				for (uint i = 0; i < numPoints; ++i)
 				{
 					QPointF p = getPoint(ds);
 					points.append(p);
 				}
+				pTypes.reserve(numPoints);
 				for (uint i = 0; i < numPoints; ++i)
 				{
 					quint8 ptyc;
@@ -1968,6 +1970,7 @@
 		quint32 dLen;
 		ds >> ind >> len;
 		ds >> dLen;
+		dxTxt.reserve(len);
 		for (quint16 aa = 0; aa < len; aa++)
 		{
 			quint32 ptyc;
@@ -2846,6 +2849,8 @@
 			ds >> cCount;
 			QList<float> posit;
 			QList<quint32> facts;
+			posit.reserve(cCount);
+			facts.reserve(cCount);
 			for (quint32 c = 0; c < cCount; c++)
 			{
 				float fact;
@@ -2924,6 +2929,8 @@
 			ds >> cCount;
 			QList<float> posit;
 			QList<quint32> facts;
+			posit.reserve(cCount);
+			facts.reserve(cCount);
 			for (quint32 c = 0; c < cCount; c++)
 			{
 				float fact;
@@ -4711,6 +4718,7 @@
 			QVector<QRgb> colorTbl;
 			quint32 palFlags, colorsUsed;
 			dsB >> palFlags >> colorsUsed;
+			colorTbl.reserve(colorsUsed);
 			for (quint32 pa = 0; pa < colorsUsed; pa++)
 			{
 				quint32 brushID;
@@ -4740,6 +4748,7 @@
 			QVector<QRgb> colorTbl;
 			quint32 palFlags, colorsUsed;
 			dsB >> palFlags >> colorsUsed;
+			colorTbl.reserve(colorsUsed);
 			for (quint32 pa = 0; pa < colorsUsed; pa++)
 			{
 				quint32 brushID;
@@ -4779,6 +4788,7 @@
 			QVector<QRgb> colorTbl;
 			quint32 palFlags, colorsUsed;
 			dsB >> palFlags >> colorsUsed;
+			colorTbl.reserve(colorsUsed);
 			for (quint32 pa = 0; pa < colorsUsed; pa++)
 			{
 				quint32 brushID;

Modified: trunk/Scribus/scribus/plugins/import/xfig/importxfig.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/plugins/import/xfig/importxfig.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/xfig/importxfig.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/xfig/importxfig.cpp	Fri Nov  6 00:03:19 2020
@@ -1553,6 +1553,7 @@
 {
 	int ac = m_Doc->Items->count();
 	QList<PageItem*> itemList;
+	itemList.reserve(ac);
 	for (int as = oldDocItemCount; as < ac; ++as)
 	{
 		itemList.append(m_Doc->Items->takeAt(oldDocItemCount));

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Fri Nov  6 00:03:19 2020
@@ -2328,9 +2328,9 @@
 				allItems = currItem->getAllChildren();
 			else
 				allItems.append(currItem);
-			for (int ii = 0; ii < allItems.count(); ii++)
+			for (int j = 0; j < allItems.count(); j++)
 			{
-				PageItem* item = allItems.at(ii);
+				PageItem* item = allItems.at(j);
 				if ((item->itemType() == PageItem::ImageFrame) && (!item->isLatexFrame()) && (!item->isOSGFrame()))
 				{
 					enablePicManager = true;

Modified: trunk/Scribus/scribus/ui/customfdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/ui/customfdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/customfdialog.cpp	Fri Nov  6 00:03:19 2020
@@ -64,9 +64,9 @@
 
 ImIconProvider::ImIconProvider()
 {
-	fmts.clear();
 	QString tmp[] = {"eps", "epsi", "gif", "png", "jpg", "jpeg", "xpm", "tif", "tiff", "bmp", "pbm", "pgm", "ppm", "xbm", "xpm", "psd", "pat"};
 	size_t arraySize = sizeof(tmp) / sizeof(*tmp);
+	fmts.reserve(arraySize);
 	for (size_t i = 0; i < arraySize; ++i)
 		fmts.append(tmp[i]);
 	IconManager& im=IconManager::instance();
@@ -708,4 +708,4 @@
 	if (optionCombo)
 		return optionCombo->currentIndex();
 	return -1;
-}
+}

Modified: trunk/Scribus/scribus/ui/prefs_tableofcontents.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/ui/prefs_tableofcontents.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_tableofcontents.cpp	(original)
+++ trunk/Scribus/scribus/ui/prefs_tableofcontents.cpp	Fri Nov  6 00:03:19 2020
@@ -116,16 +116,16 @@
 	if (m_Doc != nullptr)
 	{
 		QList<PageItem*> allItems;
-		for (int a = 0; a < m_Doc->DocItems.count(); ++a)
+		for (int i = 0; i < m_Doc->DocItems.count(); ++i)
 		{
-			PageItem *currItem = m_Doc->DocItems.at(a);
+			PageItem *currItem = m_Doc->DocItems.at(i);
 			if (currItem->isGroup())
 				allItems = currItem->getAllChildren();
 			else
 				allItems.append(currItem);
-			for (int ii = 0; ii < allItems.count(); ii++)
+			for (int j = 0; j < allItems.count(); j++)
 			{
-				currItem = allItems.at(ii);
+				currItem = allItems.at(j);
 				if (currItem->itemType() == PageItem::TextFrame)
 					itemDestFrameComboBox->addItem(currItem->itemName());
 			}

Modified: trunk/Scribus/scribus/ui/printdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/ui/printdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/printdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/printdialog.cpp	Fri Nov  6 00:03:19 2020
@@ -629,10 +629,8 @@
 QStringList PrintDialog::allSeparations()
 {
 	QStringList ret;
-	for (int a = 1; a < separationsCombo->count(); ++a)
-	{
-		ret.append(separationsCombo->itemText(a));
-	}
+	for (int i = 1; i < separationsCombo->count(); ++i)
+		ret.append(separationsCombo->itemText(i));
 	return ret;
 }
 

Modified: trunk/Scribus/scribus/util_math.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24185&path=/trunk/Scribus/scribus/util_math.cpp
==============================================================================
--- trunk/Scribus/scribus/util_math.cpp	(original)
+++ trunk/Scribus/scribus/util_math.cpp	Fri Nov  6 00:03:19 2020
@@ -67,6 +67,7 @@
 	QPainterPath pts;
 	// calculate corner Points first
 	QList<QPointF> cornerPoints;
+	cornerPoints.reserve(cx);
 	for (uint x = 0; x < cx; ++x)
 	{
 		sc = seg * x + 180.0 + rota;




More information about the scribus-commit mailing list