r17743 by jghali - #10968: Text copy/paste is slow

scribus-commit scribus-commit at lists.scribus.net
Mon Jul 30 22:15:11 UTC 2012


Author: jghali
Date: Mon Jul 30 22:15:11 2012
New Revision: 17743

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17743
Log:
#10968: Text copy/paste is slow

Modified:
    trunk/Scribus/scribus/desaxe/actions.h
    trunk/Scribus/scribus/desaxe/digester.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/text/storytext.cpp

Modified: trunk/Scribus/scribus/desaxe/actions.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17743&path=/trunk/Scribus/scribus/desaxe/actions.h
==============================================================================
--- trunk/Scribus/scribus/desaxe/actions.h (original)
+++ trunk/Scribus/scribus/desaxe/actions.h Mon Jul 30 22:15:11 2012
@@ -34,6 +34,7 @@
                                                
 	virtual void end(const Xml_string&)             {}
 	virtual void chars(const Xml_string&)           {}
+	virtual void reset()                            {}
 
 	Digester* dig;
 private:
@@ -86,6 +87,11 @@
 			++body->refs;
 		}
 		return *this;
+	}
+
+	virtual void reset()
+	{
+		body->reset();
 	}
 
 protected:

Modified: trunk/Scribus/scribus/desaxe/digester.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17743&path=/trunk/Scribus/scribus/desaxe/digester.cpp
==============================================================================
--- trunk/Scribus/scribus/desaxe/digester.cpp (original)
+++ trunk/Scribus/scribus/desaxe/digester.cpp Mon Jul 30 22:15:11 2012
@@ -164,7 +164,7 @@
 	for(it=rules.begin(); it!=rules.end(); ++it)
 	{
 #ifdef DESAXE_DEBUG
-		std::cerr << "B " << it->first << " " << typeid(it->second).name() << "\n";
+		std::cerr << "B " << it->first.toStdString() << " " << typeid(it->second).name() << "\n";
 #endif
 		const_cast<Action&>(it->second).begin(tag, attr);
 	}
@@ -177,7 +177,7 @@
 	for(it=rules.rbegin(); it!=rules.rend(); ++it)
 	{
 #ifdef DESAXE_DEBUG
-		std::cerr << "E " << it->first << " " << typeid(it->second).name() << "\n";
+		std::cerr << "E " << it->first.toStdString() << " " << typeid(it->second).name() << "\n";
 #endif
 		const_cast<Action&>(it->second).end(tag);
 	}
@@ -191,7 +191,7 @@
 	for(it=rules.begin(); it!=rules.end(); ++it)
 	{
 #ifdef DESAXE_DEBUG
-		std::cerr << "C " << it->first << " " << typeid(it->second).name() << "\n";
+		std::cerr << "C " << it->first.toStdString() << " " << typeid(it->second).name() << "\n";
 #endif
 		const_cast<Action&>(it->second).chars(text);
 	}
@@ -243,6 +243,9 @@
 inline
 void RuleState::reset()
 {
+	std::vector<rule_t>::iterator it;
+	for (it = rules.begin(); it != rules.end(); ++it)
+		it->second.reset();
 	stateStack.clear();
 	if (!valid)
 		compileDFA();

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17743&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Mon Jul 30 22:15:11 2012
@@ -5137,15 +5137,14 @@
 
 			if (ScMimeData::clipboardHasScribusText())
 			{
-				Serializer dig(*doc); // TODO: do we really need a new serializer here?
-				dig.store<ScribusDoc>("<scribusdoc>", doc);
-				StoryText::desaxeRules("/", dig, "SCRIBUSTEXT");
-				dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
+				Serializer *textSerializer = doc->textSerializer();
+				textSerializer->reset();
+				textSerializer->store<ScribusDoc>("<scribusdoc>", doc);
 
 				QByteArray xml = ScMimeData::clipboardScribusText();
-				dig.parseMemory(xml, xml.length());
-
-				StoryText* story = dig.result<StoryText>();
+				textSerializer->parseMemory(xml, xml.length());
+
+				StoryText* story = textSerializer->result<StoryText>();
 				if (UndoManager::undoEnabled())
 				{
 					ScItemState<StoryText> *is = new ScItemState<StoryText>(Um::Paste);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17743&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Mon Jul 30 22:15:11 2012
@@ -202,6 +202,7 @@
 	m_View(0),
 	m_guardedObject(this),
 	m_serializer(NULL),
+	m_tserializer(NULL),
 	is12doc(false),
 	NrItems(0),
 	First(1), Last(0),
@@ -295,6 +296,7 @@
 	m_View(0),
 	m_guardedObject(this),
 	m_serializer(NULL),
+	m_tserializer(NULL),
 	is12doc(false),
 	NrItems(0),
 	First(1), Last(0),
@@ -683,6 +685,8 @@
 		delete docHyphenator;
 	if (m_serializer)
 		delete m_serializer;
+	if (m_tserializer)
+		delete m_tserializer;
 	ScCore->fileWatcher->start();
 }
 
@@ -15423,6 +15427,16 @@
 	return m_serializer;
 }
 
+Serializer *ScribusDoc::textSerializer()
+{
+	if (!m_tserializer) {
+		m_tserializer = new Serializer (*this);
+		StoryText::desaxeRules("/", *m_tserializer, "SCRIBUSTEXT");
+		m_tserializer->addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
+	}
+	Q_ASSERT(m_tserializer);
+	return m_tserializer;
+}
 
 void ScribusDoc::RotMode(const int& val)
 {

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17743&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Mon Jul 30 22:15:11 2012
@@ -1148,6 +1148,8 @@
 	QMap<PageItem*, QString> getDocItemNames(PageItem::ItemType itemType);
 	//! \brief Returns a serializer for this document
 	Serializer *serializer();
+	//! \brief Returns a text serializer for this document, used to paste text chunks
+	Serializer *textSerializer();
 
 	//! \brief Get rotation mode
 	int RotMode() const {return rotMode;}
@@ -1184,7 +1186,7 @@
 	ScribusMainWindow* m_ScMW;
 	ScribusView* m_View;
 	ScGuardedObject<ScribusDoc> m_guardedObject;
-	Serializer *m_serializer;
+	Serializer *m_serializer, *m_tserializer;
 	QString currentEditedSymbol;
 	int currentEditedIFrame;
 

Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17743&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp (original)
+++ trunk/Scribus/scribus/text/storytext.cpp Mon Jul 30 22:15:11 2012
@@ -2103,6 +2103,11 @@
 		if (lastStyle)
 			delete lastStyle;
 	}
+
+	virtual void reset()
+	{
+		numPara = 0;
+	}
 	
 	void begin(const Xml_string& tag, Xml_attr attr)
 	{




More information about the scribus-commit mailing list