View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0008220 | Scribus | Plug-ins | public | 2009-06-28 10:30 | 2009-08-10 22:15 |
Reporter | Shaforostoff | Assigned To | jghali | ||
Priority | normal | Severity | tweak | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.3.5svn | ||||
Fixed in Version | 1.5.0svn | ||||
Summary | 0008220: [patch] make two-byte conversion happening much less often on file load | ||||
Description | this patch makes loading files with alot of ITEXTs faster. on iezasnow12-8.sla from bug 1036 it shows %20 performance boost (18 seconds instead of 22) this is achieved by avoiding two-byte conversion happening on each GetItemText() call. profiling with callgrind shows that QString::fromLatin1 is called only 0000200:0000300 000 as opposed to 5 mln. I also made few other obvious changes that make code more readable, like switching to 'foreach' loop in 2 places | ||||
Additional Information | there is performance measurement code left in patch that can be easily removed or commented out. | ||||
Tags | No tags attached. | ||||
Patch | |||||
2009-06-28 10:30
|
play-nice-with-unicode.patch (22,726 bytes)
Index: scribus134format_save.cpp =================================================================== --- scribus134format_save.cpp (revision 13730) +++ scribus134format_save.cpp (working copy) @@ -406,10 +406,10 @@ docu.writeAttribute("WORD", hyit.key()); docu.writeAttribute("HYPHENATED", hyit.value()); } - for (QSet<QString>::Iterator hyit2 = m_Doc->docHyphenator->ignoredWords.begin(); hyit2 != m_Doc->docHyphenator->ignoredWords.end(); ++hyit2) + foreach (const QString& ignoredWord, m_Doc->docHyphenator->ignoredWords) { docu.writeEmptyElement("IGNORE"); - docu.writeAttribute("WORD", (*hyit2)); + docu.writeAttribute("WORD", ignoredWord); } docu.writeEndElement(); } @@ -482,9 +482,9 @@ docu.writeEmptyElement("Tabs"); docu.writeAttribute("Type", (style.tabValues().at(a)).tabType); docu.writeAttribute("Pos", (style.tabValues().at(a)).tabPosition); - QString tabCh = ""; - if (!(style.tabValues().at(a)).tabFillChar.isNull()) - tabCh = QString((style.tabValues().at(a)).tabFillChar); + QString tabCh = QString((style.tabValues().at(a)).tabFillChar); + if (tabCh.at(0).isNull()) + tabCh.clear(); docu.writeAttribute("Fill", tabCh); } } @@ -534,7 +534,7 @@ { if ( ! style.parent().isEmpty() ) docu.writeAttribute("CPARENT", style.parent()); - if ( ! style.isInhFont()) + if ( ! style.isInhFont()) docu.writeAttribute("FONT", style.font().scName()); if ( ! style.isInhFontSize()) docu.writeAttribute("FONTSIZE", style.fontSize() / 10.0); @@ -883,29 +883,16 @@ void Scribus134Format::WritePages(ScribusDoc *doc, ScXmlStreamWriter& docu, QProgressBar *dia2, uint maxC, bool master) { uint ObCount = maxC; - Page *page; - uint pages; QDomElement pg; QString tmp; - if (master) - pages = doc->MasterPages.count(); - else - pages = doc->DocPages.count(); - for(uint i = 0; i < pages; ++i) + QString elementName=master?"MASTERPAGE":"PAGE"; + foreach(Page *page, (master?doc->MasterPages:doc->DocPages)) { ObCount++; if (dia2 != 0) dia2->setValue(ObCount); - if (master) - { - docu.writeStartElement("MASTERPAGE"); - page = doc->MasterPages.at(i); - } - else - { - docu.writeStartElement("PAGE"); - page = doc->DocPages.at(i); - } + docu.writeStartElement(elementName); + docu.writeAttribute("PAGEXPOS",page->xOffset()); docu.writeAttribute("PAGEYPOS",page->yOffset()); docu.writeAttribute("PAGEWIDTH",page->width()); Index: scribus134format.cpp =================================================================== --- scribus134format.cpp (revision 13730) +++ scribus134format.cpp (working copy) @@ -141,12 +141,13 @@ // Not gzip encoded, just load it loadRawText(fileName, docBytes); } - QString docText(""); + int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW "); - if (startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.3.4") >= 0) || (docBytes.mid(startElemPos, 64).indexOf("Version=\"1.3.5") >= 0))) - docText = QString::fromUtf8(docBytes); - else + bool ok=(startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.3.4") >= 0) || (docBytes.mid(startElemPos, 64).indexOf("Version=\"1.3.5") >= 0))); + if (!ok) return QString::null; + + QString docText = QString::fromUtf8(docBytes); if (docText.endsWith(QChar(10)) || docText.endsWith(QChar(13))) docText.truncate(docText.length()-1); return docText; @@ -160,6 +161,8 @@ bool Scribus134Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */) { + QTime time;time.start(); + if (m_Doc==0 || m_AvailableFonts==0) { Q_ASSERT(m_Doc==0 || m_AvailableFonts==0); @@ -213,7 +216,7 @@ if (elem.hasAttribute("Version")) newVersion = true; QDomNode DOC=elem.firstChild(); - if (m_mwProgressBar!=0) + if (m_mwProgressBar) { m_mwProgressBar->setMaximum(DOC.childNodes().count()); m_mwProgressBar->setValue(0); @@ -849,14 +852,11 @@ QDomElement hyElem = hyelm.toElement(); if (hyElem.tagName()=="EXCEPTION") { - QString word = hyElem.attribute("WORD"); - QString hyph = hyElem.attribute("HYPHENATED"); - m_Doc->docHyphenator->specialWords.insert(word, hyph); + m_Doc->docHyphenator->specialWords.insert(hyElem.attribute("WORD"), hyElem.attribute("HYPHENATED")); } else if (hyElem.tagName()=="IGNORE") { - QString word = hyElem.attribute("WORD"); - m_Doc->docHyphenator->ignoredWords.insert(word); + m_Doc->docHyphenator->ignoredWords.insert(hyElem.attribute("WORD")); } hyelm = hyelm.nextSibling(); } @@ -864,7 +864,6 @@ if ((pg.tagName()=="PAGE") || (pg.tagName()=="MASTERPAGE")) { a = pg.attribute("NUM").toInt(); - PgNam = ""; PgNam = pg.attribute("NAM", ""); if (pg.tagName()=="MASTERPAGE" && PgNam.isEmpty()) { @@ -908,12 +907,9 @@ } //m_Doc->setUsesAutomaticTextFrames(AtFl); Apage->LeftPg=pg.attribute("LEFT", "0").toInt(); - QString Mus = ""; - Mus = pg.attribute("MNAM","Normal"); + Apage->MPageNam=""; if (!m_Doc->masterPageMode()) - Apage->MPageNam = Mus; - else - Apage->MPageNam = ""; + Apage->MPageNam = pg.attribute("MNAM","Normal"); if (pg.hasAttribute("Size")) Apage->m_pageSize = pg.attribute("Size"); if (pg.hasAttribute("Orientation")) @@ -1540,8 +1536,11 @@ if (m_Doc->AutoSave && ScCore->usingGUI()) m_Doc->autoSaveTimer->start(m_Doc->AutoSaveTime); - if (m_mwProgressBar!=0) + if (m_mwProgressBar) m_mwProgressBar->setValue(DOC.childNodes().count()); + + qWarning() << "loadFile in" << time.elapsed()<<"msecs"; + return true; // return false; } @@ -1639,178 +1638,228 @@ void Scribus134Format::GetCStyle(const QDomElement *it, ScribusDoc *doc, CharStyle & newStyle) { - if (it->hasAttribute("CNAME")) - newStyle.setName(it->attribute("CNAME")); + static const QString CNAME("CNAME"); + if (it->hasAttribute(CNAME)) + newStyle.setName(it->attribute(CNAME)); + // The default style attribute must be correctly set before trying to assign a parent - if (newStyle.hasName() && it->hasAttribute("DefaultStyle")) - newStyle.setDefaultStyle(it->attribute("DefaultStyle").toInt()); - else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle) - newStyle.setDefaultStyle(true); - else - newStyle.setDefaultStyle(false); - if (it->hasAttribute("CPARENT")) - newStyle.setParent(it->attribute("CPARENT")); - if (it->hasAttribute("FONT")) - newStyle.setFont(m_AvailableFonts->findFont(it->attribute("FONT"),doc)); + static const QString DefaultStyle("DefaultStyle"); + newStyle.setDefaultStyle( + (newStyle.hasName() && it->hasAttribute(DefaultStyle))? + bool(it->attribute(DefaultStyle).toInt()): + newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle + ); + + static const QString CPARENT("CPARENT"); + if (it->hasAttribute(CPARENT)) + newStyle.setParent(it->attribute(CPARENT)); + + static const QString FONT("FONT"); + if (it->hasAttribute(FONT)) + newStyle.setFont(m_AvailableFonts->findFont(it->attribute(FONT),doc)); - if (it->hasAttribute("FONTSIZE")) - newStyle.setFontSize(qRound(ScCLocale::toDoubleC(it->attribute("FONTSIZE")) * 10)); + static const QString FONTSIZE("FONTSIZE"); + if (it->hasAttribute(FONTSIZE)) + newStyle.setFontSize(qRound(ScCLocale::toDoubleC(it->attribute(FONTSIZE)) * 10)); - if (it->hasAttribute("FCOLOR")) - newStyle.setFillColor(it->attribute("FCOLOR")); + static const QString FCOLOR("FCOLOR"); + if (it->hasAttribute(FCOLOR)) + newStyle.setFillColor(it->attribute(FCOLOR)); - if (it->hasAttribute("KERN")) - newStyle.setTracking(qRound(ScCLocale::toDoubleC(it->attribute("KERN")) * 10)); + static const QString KERN("KERN"); + if (it->hasAttribute(KERN)) + newStyle.setTracking(qRound(ScCLocale::toDoubleC(it->attribute(KERN)) * 10)); - if (it->hasAttribute("FSHADE")) - newStyle.setFillShade(it->attribute("FSHADE").toInt()); + static const QString FSHADE("FSHADE"); + if (it->hasAttribute(FSHADE)) + newStyle.setFillShade(it->attribute(FSHADE).toInt()); - if (it->hasAttribute("EFFECTS")) - newStyle.setFeatures(static_cast<StyleFlag>(it->attribute("EFFECTS").toInt()).featureList()); + static const QString EFFECTS("EFFECTS"); + if (it->hasAttribute(EFFECTS)) + newStyle.setFeatures(static_cast<StyleFlag>(it->attribute(EFFECTS).toInt()).featureList()); - if (it->hasAttribute("EFFECT")) - newStyle.setFeatures(static_cast<StyleFlag>(it->attribute("EFFECT").toInt()).featureList()); + static const QString EFFECT("EFFECT"); + if (it->hasAttribute(EFFECT)) + newStyle.setFeatures(static_cast<StyleFlag>(it->attribute(EFFECT).toInt()).featureList()); - if (it->hasAttribute("FEATURES")) - newStyle.setFeatures(it->attribute("FEATURES").split( " ", QString::SkipEmptyParts)); + static const QString FEATURES("FEATURES"); + if (it->hasAttribute(FEATURES)) + newStyle.setFeatures(it->attribute(FEATURES).split(' ', QString::SkipEmptyParts)); - if (it->hasAttribute("SCOLOR")) + static const QString SCOLOR("SCOLOR"); + if (it->hasAttribute(SCOLOR)) newStyle.setStrokeColor(it->attribute("SCOLOR", CommonStrings::None)); - if (it->hasAttribute("SSHADE")) - newStyle.setStrokeShade(it->attribute("SSHADE").toInt()); + static const QString SSHADE("SSHADE"); + if (it->hasAttribute(SSHADE)) + newStyle.setStrokeShade(it->attribute(SSHADE).toInt()); - if (it->hasAttribute("SCALEH")) - newStyle.setScaleH(qRound(ScCLocale::toDoubleC(it->attribute("SCALEH")) * 10)); + static const QString SCALEH("SCALEH"); + if (it->hasAttribute(SCALEH)) + newStyle.setScaleH(qRound(ScCLocale::toDoubleC(it->attribute(SCALEH)) * 10)); - if (it->hasAttribute("SCALEV")) - newStyle.setScaleV(qRound(ScCLocale::toDoubleC(it->attribute("SCALEV")) * 10)); + static const QString SCALEV("SCALEV"); + if (it->hasAttribute(SCALEV)) + newStyle.setScaleV(qRound(ScCLocale::toDoubleC(it->attribute(SCALEV)) * 10)); - if (it->hasAttribute("BASEO")) - newStyle.setBaselineOffset(qRound(ScCLocale::toDoubleC(it->attribute("BASEO")) * 10)); + static const QString BASEO("BASEO"); + if (it->hasAttribute(BASEO)) + newStyle.setBaselineOffset(qRound(ScCLocale::toDoubleC(it->attribute(BASEO)) * 10)); - if (it->hasAttribute("TXTSHX")) - newStyle.setShadowXOffset(qRound(ScCLocale::toDoubleC(it->attribute("TXTSHX")) * 10)); + static const QString TXTSHX("TXTSHX"); + if (it->hasAttribute(TXTSHX)) + newStyle.setShadowXOffset(qRound(ScCLocale::toDoubleC(it->attribute(TXTSHX)) * 10)); - if (it->hasAttribute("TXTSHY")) - newStyle.setShadowYOffset(qRound(ScCLocale::toDoubleC(it->attribute("TXTSHY")) * 10)); + static const QString TXTSHY("TXTSHY"); + if (it->hasAttribute(TXTSHY)) + newStyle.setShadowYOffset(qRound(ScCLocale::toDoubleC(it->attribute(TXTSHY)) * 10)); - if (it->hasAttribute("TXTOUT")) - newStyle.setOutlineWidth(qRound(ScCLocale::toDoubleC(it->attribute("TXTOUT")) * 10)); + static const QString TXTOUT("TXTOUT"); + if (it->hasAttribute(TXTOUT)) + newStyle.setOutlineWidth(qRound(ScCLocale::toDoubleC(it->attribute(TXTOUT)) * 10)); - if (it->hasAttribute("TXTULP")) - newStyle.setUnderlineOffset(qRound(ScCLocale::toDoubleC(it->attribute("TXTULP")) * 10)); + static const QString TXTULP("TXTULP"); + if (it->hasAttribute(TXTULP)) + newStyle.setUnderlineOffset(qRound(ScCLocale::toDoubleC(it->attribute(TXTULP)) * 10)); - if (it->hasAttribute("TXTULW")) - newStyle.setUnderlineWidth(qRound(ScCLocale::toDoubleC(it->attribute("TXTULW")) * 10)); + static const QString TXTULW("TXTULW"); + if (it->hasAttribute(TXTULW)) + newStyle.setUnderlineWidth(qRound(ScCLocale::toDoubleC(it->attribute(TXTULW)) * 10)); - if (it->hasAttribute("TXTSTP")) - newStyle.setStrikethruOffset(qRound(ScCLocale::toDoubleC(it->attribute("TXTSTP")) * 10)); + static const QString TXTSTP("TXTSTP"); + if (it->hasAttribute(TXTSTP)) + newStyle.setStrikethruOffset(qRound(ScCLocale::toDoubleC(it->attribute(TXTSTP)) * 10)); - if (it->hasAttribute("TXTSTW")) - newStyle.setStrikethruWidth(qRound(ScCLocale::toDoubleC(it->attribute("TXTSTW")) * 10)); + static const QString TXTSTW("TXTSTW"); + if (it->hasAttribute(TXTSTW)) + newStyle.setStrikethruWidth(qRound(ScCLocale::toDoubleC(it->attribute(TXTSTW)) * 10)); - if (it->hasAttribute("SHORTCUT")) - newStyle.setShortcut(it->attribute("SHORTCUT")); + static const QString SHORTCUT("SHORTCUT"); + if (it->hasAttribute(SHORTCUT)) + newStyle.setShortcut(it->attribute(SHORTCUT)); - if (it->hasAttribute("wordTrack")) - newStyle.setWordTracking(ScCLocale::toDoubleC(it->attribute("wordTrack"))); + static const QString wordTrack("wordTrack"); + if (it->hasAttribute(wordTrack)) + newStyle.setWordTracking(ScCLocale::toDoubleC(it->attribute(wordTrack))); -} +} void Scribus134Format::GetItemText(QDomElement *it, ScribusDoc *doc, PageItem* obj, LastStyles* last, bool impo, bool VorLFound) { +// QTime a;a.start(); +// static int COUNTER=0; + + + //two-byte conversion is happening less often now + static const QString MINUSONE("-1"); QString tmp2, tmpf; CharStyle newStyle; GetCStyle(it, doc, newStyle); - if (it->hasAttribute("Unicode")) + if (it->hasAttribute(QLatin1String("Unicode"))) { - tmp2 = QChar(it->attribute("Unicode").toUInt()); + tmp2 = QChar(it->attribute(QLatin1String("Unicode")).toUInt()); } else { - tmp2 = it->attribute("CH"); + tmp2 = it->attribute(QLatin1String("CH")); // legacy stuff: - tmp2.replace(QRegExp("\r"), QChar(13)); - tmp2.replace(QRegExp("\n"), QChar(13)); - tmp2.replace(QRegExp("\t"), QChar(9)); + tmp2.replace('\r', QChar(13)); + tmp2.replace('\n', QChar(13)); + tmp2.replace('\t', QChar(9)); } // more legacy stuff: - if (it->hasAttribute("CFONT")) - newStyle.setFont(m_AvailableFonts->findFont(it->attribute("CFONT"), doc)); + static const QString CFONT("CFONT"); + if (it->hasAttribute(CFONT)) + newStyle.setFont(m_AvailableFonts->findFont(it->attribute(CFONT), doc)); - if (it->hasAttribute("CSIZE")) - newStyle.setFontSize(qRound(ScCLocale::toDoubleC(it->attribute("CSIZE")) * 10)); + static const QString CSIZE("CSIZE"); + if (it->hasAttribute(CSIZE)) + newStyle.setFontSize(qRound(ScCLocale::toDoubleC(it->attribute(CSIZE)) * 10)); - if (it->hasAttribute("CCOLOR")) - newStyle.setFillColor(it->attribute("CCOLOR")); + static const QString CCOLOR("CCOLOR"); + if (it->hasAttribute(CCOLOR)) + newStyle.setFillColor(it->attribute(CCOLOR)); - if (it->hasAttribute("CEXTRA")) - newStyle.setTracking(qRound(ScCLocale::toDoubleC(it->attribute("CEXTRA")) / ScCLocale::toDoubleC(it->attribute("CSIZE")) * 1000.0)); - else if (it->hasAttribute("CKERN")) - newStyle.setTracking(it->attribute("CKERN").toInt()); + static const QString CEXTRA("CEXTRA"); + if (it->hasAttribute(CEXTRA)) + newStyle.setTracking(qRound(ScCLocale::toDoubleC(it->attribute(CEXTRA)) / ScCLocale::toDoubleC(it->attribute(CSIZE)) * 1000.0)); + else if (it->hasAttribute(QLatin1String("CKERN"))) + newStyle.setTracking(it->attribute(QLatin1String("CKERN")).toInt()); - if (it->hasAttribute("CSHADE")) - newStyle.setFillShade(it->attribute("CSHADE").toInt()); + static const QString CSHADE("CSHADE"); + if (it->hasAttribute(CSHADE)) + newStyle.setFillShade(it->attribute(CSHADE).toInt()); - if (it->hasAttribute("CSTYLE")) - newStyle.setFeatures(static_cast<StyleFlag>(it->attribute("CSTYLE").toInt()).featureList()); - - QString pstylename = it->attribute("PSTYLE", ""); - int calign = it->attribute("CALIGN", "-1").toInt(); + static const QString CSTYLE("CSTYLE"); + if (it->hasAttribute(CSTYLE)) + newStyle.setFeatures(static_cast<StyleFlag>(it->attribute(CSTYLE).toInt()).featureList()); - int ab = it->attribute("CAB", "-1").toInt(); + QString pstylename = it->attribute(QLatin1String("PSTYLE"), ""); + int calign = it->attribute(QLatin1String("CALIGN"), MINUSONE).toInt(); + + int ab = it->attribute(QLatin1String("CAB"), MINUSONE).toInt(); if (ab >= 5) { pstylename = doc->paragraphStyles()[ab-5].name(); calign = -1; } else if (ab >= 0) { - pstylename = ""; + pstylename=""; calign = ab; } - if (it->hasAttribute("CSTROKE")) - newStyle.setStrokeColor(it->attribute("CSTROKE", CommonStrings::None)); + static const QString CSTROKE("CSTROKE"); + if (it->hasAttribute(CSTROKE)) + newStyle.setStrokeColor(it->attribute(CSTROKE, CommonStrings::None)); - if (it->hasAttribute("CSHADE2")) - newStyle.setStrokeShade(it->attribute("CSHADE2", "100").toInt()); + static const QString CSHADE2("CSHADE2"); + if (it->hasAttribute(CSHADE2)) + newStyle.setStrokeShade(it->attribute(CSHADE2, QLatin1String("100")).toInt()); - if (it->hasAttribute("CSCALE")) - newStyle.setScaleH(qMin(qMax(qRound(ScCLocale::toDoubleC(it->attribute("CSCALE"), 100.0) * 10), 100), 4000)); + static const QString CSCALE("CSCALE"); + if (it->hasAttribute(CSCALE)) + newStyle.setScaleH(qMin(qMax(qRound(ScCLocale::toDoubleC(it->attribute(CSCALE), 100.0) * 10), 100), 4000)); - if (it->hasAttribute("CSCALEV")) - newStyle.setScaleV(qMin(qMax(qRound(ScCLocale::toDoubleC(it->attribute("CSCALEV"), 100.0) * 10), 100), 4000)); + static const QString CSCALEV("CSCALEV"); + if (it->hasAttribute(CSCALEV)) + newStyle.setScaleV(qMin(qMax(qRound(ScCLocale::toDoubleC(it->attribute(CSCALEV), 100.0) * 10), 100), 4000)); - if (it->hasAttribute("CBASE")) - newStyle.setBaselineOffset(qRound(ScCLocale::toDoubleC(it->attribute("CBASE")) * 10)); + static const QString CBASE("CBASE"); + if (it->hasAttribute(CBASE)) + newStyle.setBaselineOffset(qRound(ScCLocale::toDoubleC(it->attribute(CBASE)) * 10)); - if (it->hasAttribute("CSHX")) - newStyle.setShadowXOffset(qRound(ScCLocale::toDoubleC(it->attribute("CSHX"), 5.0) * 10)); + static const QString CSHX("CSHX"); + if (it->hasAttribute(CSHX)) + newStyle.setShadowXOffset(qRound(ScCLocale::toDoubleC(it->attribute(CSHX), 5.0) * 10)); - if (it->hasAttribute("CSHY")) - newStyle.setShadowYOffset(qRound(ScCLocale::toDoubleC(it->attribute("CSHY"), -5.0) * 10)); + static const QString CSHY("CSHY"); + if (it->hasAttribute(CSHY)) + newStyle.setShadowYOffset(qRound(ScCLocale::toDoubleC(it->attribute(CSHY), -5.0) * 10)); - if (it->hasAttribute("COUT")) - newStyle.setOutlineWidth(qRound(ScCLocale::toDoubleC(it->attribute("COUT"), 1.0) * 10)); + static const QString COUT("COUT"); + if (it->hasAttribute(COUT)) + newStyle.setOutlineWidth(qRound(ScCLocale::toDoubleC(it->attribute(COUT), 1.0) * 10)); - if (it->hasAttribute("CULP")) - newStyle.setUnderlineOffset(qRound(ScCLocale::toDoubleC(it->attribute("CULP"), -0.1) * 10)); + static const QString CULP("CULP"); + if (it->hasAttribute(CULP)) + newStyle.setUnderlineOffset(qRound(ScCLocale::toDoubleC(it->attribute(CULP), -0.1) * 10)); - if (it->hasAttribute("CULW")) - newStyle.setUnderlineWidth(qRound(ScCLocale::toDoubleC(it->attribute("CULW"), -0.1) * 10)); + static const QString CULW("CULW"); + if (it->hasAttribute(CULW)) + newStyle.setUnderlineWidth(qRound(ScCLocale::toDoubleC(it->attribute(CULW), -0.1) * 10)); + static const QString CSTP("CSTP"); + if (it->hasAttribute(CSTP)) + newStyle.setStrikethruOffset(qRound(ScCLocale::toDoubleC(it->attribute(CSTP), -0.1) * 10)); - if (it->hasAttribute("CSTP")) - newStyle.setStrikethruOffset(qRound(ScCLocale::toDoubleC(it->attribute("CSTP"), -0.1) * 10)); + static const QString CSTW("CSTW"); + if (it->hasAttribute(CSTW)) + newStyle.setStrikethruWidth(qRound(ScCLocale::toDoubleC(it->attribute(CSTW), -0.1) * 10)); - if (it->hasAttribute("CSTW")) - newStyle.setStrikethruWidth(qRound(ScCLocale::toDoubleC(it->attribute("CSTW"), -0.1) * 10)); - fixLegacyCharStyle(newStyle); if (impo && ab >= 0 && VorLFound) @@ -1819,11 +1868,11 @@ last->ParaStyle = pstylename; // end of legacy stuff - int iobj = it->attribute("COBJ", "-1").toInt(); + int iobj = it->attribute(QLatin1String("COBJ"), MINUSONE).toInt(); for (int cxx=0; cxx<tmp2.length(); ++cxx) { - QChar ch = tmp2.at(cxx); + QChar ch = tmp2.at(cxx); { // Legacy mode if (ch == QChar(5)) ch = SpecialChars::PARSEP; @@ -1898,6 +1947,11 @@ pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(calign)); obj->itemText.applyStyle(obj->itemText.length()-1, pstyle); } +/* + COUNTER+=a.elapsed(); + qWarning() << "GetItemText" << a.elapsed() << COUNTER << tmp2.size() << tmp2 + << (uint)it << (uint)doc << (uint)obj << (uint)last << impo << VorLFound; +*/ } @@ -1909,10 +1963,8 @@ // The default style attribute must be correctly set before trying to assign a parent if (pg.hasAttribute("DefaultStyle")) vg.setDefaultStyle(pg.attribute("DefaultStyle").toInt()); - else if (vg.name() == CommonStrings::DefaultParagraphStyle || vg.name() == CommonStrings::trDefaultParagraphStyle) - vg.setDefaultStyle(true); else - vg.setDefaultStyle(false); + vg.setDefaultStyle(vg.name() == CommonStrings::DefaultParagraphStyle || vg.name() == CommonStrings::trDefaultParagraphStyle); vg.setParent(pg.attribute("PARENT", "")); if (pg.hasAttribute("LINESPMode")) vg.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(pg.attribute("LINESPMode").toInt())); @@ -2433,19 +2485,21 @@ currItem->BaseOffs = ScCLocale::toDoubleC( obj->attribute("BASEOF"), 0.0); currItem->textPathType = obj->attribute("textPathType", "0").toInt(); currItem->textPathFlipped = static_cast<bool>(obj->attribute("textPathFlipped", "0").toInt()); + + PageItem::TextFlowMode fMode=PageItem::TextFlowDisabled; if ( obj->hasAttribute("TEXTFLOWMODE") ) - currItem->setTextFlowMode((PageItem::TextFlowMode) obj->attribute("TEXTFLOWMODE", "0").toInt()); + fMode=(PageItem::TextFlowMode) obj->attribute("TEXTFLOWMODE", "0").toInt(); else if ( obj->attribute("TEXTFLOW").toInt() ) { if (obj->attribute("TEXTFLOW2", "0").toInt()) - currItem->setTextFlowMode(PageItem::TextFlowUsesBoundingBox); + fMode=PageItem::TextFlowUsesBoundingBox; else if (obj->attribute("TEXTFLOW3", "0").toInt()) - currItem->setTextFlowMode(PageItem::TextFlowUsesContourLine); + fMode=PageItem::TextFlowUsesContourLine; else - currItem->setTextFlowMode(PageItem::TextFlowUsesFrameShape); + fMode=PageItem::TextFlowUsesFrameShape; } - else - currItem->setTextFlowMode(PageItem::TextFlowDisabled); + currItem->setTextFlowMode(fMode); + currItem->DashOffset = ScCLocale::toDoubleC( obj->attribute("DASHOFF"), 0.0); currItem->setReversed(static_cast<bool>(obj->attribute("REVERS", "0").toInt())); currItem->setLocked(static_cast<bool>(obj->attribute("LOCK", "0").toInt())); @@ -3611,4 +3665,4 @@ - +//kate: replace-tabs 0; |
2009-06-28 10:44
|
dont-confuse-cpu-with-too-much-ifs.patch (3,729 bytes)
Index: charstyle.cpp =================================================================== --- charstyle.cpp (revision 13730) +++ charstyle.cpp (working copy) @@ -287,106 +287,71 @@ { if (parent) runFeatures(parent->features(), dynamic_cast<const CharStyle*>(parent->parentStyle())); + continue; } - else if (feature == BOLD) + int set=!feature.startsWith('-'); //either 1 or 0 + int invert=feature.startsWith('-'); //either 1 or 0 + if (invert) + feature=feature.mid(1); + + if (feature == BOLD) { - // select bolder font + // (de)select bolder font } else if (feature == ITALIC) { - // select italic font + // (de)select italic font } else if (feature == UNDERLINE) { - m_Effects |= ScStyle_Underline; + m_Effects &= ~(invert*ScStyle_Underline); + m_Effects |= set*ScStyle_Underline; } else if (feature == UNDERLINEWORDS) { - m_Effects |= ScStyle_UnderlineWords; + m_Effects &= ~(invert*ScStyle_UnderlineWords); + m_Effects |= set*ScStyle_UnderlineWords; } else if (feature == STRIKETHROUGH) { - m_Effects |= ScStyle_Strikethrough; + m_Effects &= ~(invert*ScStyle_Strikethrough); + m_Effects |= set*ScStyle_Strikethrough; } else if (feature == SUPERSCRIPT) { - m_Effects |= ScStyle_Superscript; + m_Effects &= ~(invert*ScStyle_Superscript); + m_Effects |= set*ScStyle_Superscript; } else if (feature == SUBSCRIPT) { - m_Effects |= ScStyle_Subscript; + m_Effects &= ~(invert*ScStyle_Subscript); + m_Effects |= set*ScStyle_Subscript; } else if (feature == OUTLINE) { - m_Effects |= ScStyle_Outline; + m_Effects &= ~(invert*ScStyle_Outline); + m_Effects |= set*ScStyle_Outline; } else if (feature == SHADOWED) { - m_Effects |= ScStyle_Shadowed; + m_Effects &= ~(invert*ScStyle_Shadowed); + m_Effects |= set*ScStyle_Shadowed; } else if (feature == ALLCAPS) { - m_Effects |= ScStyle_AllCaps; + m_Effects &= ~(invert*ScStyle_AllCaps); + m_Effects |= set*ScStyle_AllCaps; } else if (feature == SMALLCAPS) { - m_Effects |= ScStyle_SmallCaps; + m_Effects &= ~(invert*ScStyle_SmallCaps); + m_Effects |= set*ScStyle_SmallCaps; } else if (feature == SHYPHEN) { - m_Effects |= ScStyle_HyphenationPossible; + m_Effects &= ~(invert*ScStyle_HyphenationPossible); + m_Effects |= set*ScStyle_HyphenationPossible; } - else if (feature.startsWith("-")) - { - QString no_feature = feature.mid(1); - if (no_feature == BOLD) - { - // deselect bolder font - } - else if (no_feature == ITALIC) - { - // deselect italic font - } - else if (no_feature == UNDERLINE) - { - m_Effects &= ~ScStyle_Underline; - } - else if (no_feature == UNDERLINEWORDS) - { - m_Effects &= ~ScStyle_UnderlineWords; - } - else if (no_feature == STRIKETHROUGH) - { - m_Effects &= ~ScStyle_Strikethrough; - } - else if (no_feature == SUPERSCRIPT) - { - m_Effects &= ~ScStyle_Superscript; - } - else if (no_feature == SUBSCRIPT) - { - m_Effects &= ~ScStyle_Subscript; - } - else if (no_feature == OUTLINE) - { - m_Effects &= ~ScStyle_Outline; - } - else if (no_feature == SHADOWED) - { - m_Effects &= ~ScStyle_Shadowed; - } - else if (no_feature == ALLCAPS) - { - m_Effects &= ~ScStyle_AllCaps; - } - else if (no_feature == SMALLCAPS) - { - m_Effects &= ~ScStyle_SmallCaps; - } - else { - qDebug("CharStyle: unknown feature: %s", feature.toLocal8Bit().constData()); - } - } else { qDebug("CharStyle: unknown feature: %s", feature.toLocal8Bit().constData()); } @@ -531,3 +496,5 @@ #include "charstyle.attrdefs.cxx" #undef ATTRDEF } + +//kate: replace-tabs 0; |
|
dont-confuse-cpu-with-too-much-ifs.patch tries to minimize number of comparations and consequently number of if statements, as that is what modern cpus don't like. in additioan it lowers SLOC by 30 lines. |
|
any comments? |
|
I hope this path will be integrated into 1.3.5. PLZ! |
|
That patch won't be integrated in 1.3.5 as 1.3.5 has now release candidate status. Maybe in 1.3.5.1... I adapted however the "play-nice-with-unicode" patch to 1.5.0svn scribus150format file loader. And took the opportunity to remove some unneeded legacy stuff... The old GetItemText() method, now called readItemText(), is now somewhat shorter. |
|
Patch has now been adapted to scribus134format file loader. The dont-confuse-cpu-with-too-much-ifs.patch has been applied with slight modification. |
Date Modified | Username | Field | Change |
---|---|---|---|
2009-06-28 10:30 | Shaforostoff | New Issue | |
2009-06-28 10:30 | Shaforostoff | File Added: play-nice-with-unicode.patch | |
2009-06-28 10:44 | Shaforostoff | File Added: dont-confuse-cpu-with-too-much-ifs.patch | |
2009-06-28 10:46 | Shaforostoff | Note Added: 0022045 | |
2009-07-07 15:17 | Shaforostoff | Note Added: 0022133 | |
2009-07-08 06:53 | aliB | Note Added: 0022137 | |
2009-07-15 22:03 | jghali | Note Added: 0022196 | |
2009-07-20 22:45 | jghali | Note Added: 0022218 | |
2009-07-20 22:45 | jghali | Status | new => resolved |
2009-07-20 22:45 | jghali | Fixed in Version | => 1.5.0svn |
2009-07-20 22:45 | jghali | Resolution | open => fixed |
2009-07-20 22:45 | jghali | Assigned To | => jghali |
2009-08-10 22:15 | cbradney | Status | resolved => closed |