[prev in list] [next in list] [prev in thread] [next in thread]
List: konq-bugs
Subject: [Bug 128397] Scipt causes KHTML to freeze
From: Maksim Orlovich <maksim () kde ! org>
Date: 2006-06-30 1:14:16
Message-ID: 20060630011416.22262.qmail () ktown ! kde ! org
[Download RAW message or body]
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=128397
maksim kde org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
------- Additional Comments From maksim kde org 2006-06-30 03:14 -------
SVN commit 556347 by orlovich:
Make reading of innerHTML a couple times less slow
BUG:128397
M +5 -3 html/html_elementimpl.cpp
M +4 -3 xml/dom_elementimpl.cpp
M +40 -0 xml/dom_stringimpl.cpp
M +2 -0 xml/dom_stringimpl.h
M +1 -19 xml/dom_textimpl.cpp
--- branches/KDE/3.5/kdelibs/khtml/html/html_elementimpl.cpp #556346:556347
@ -450,9 +450,11 @
DOMString HTMLElementImpl::innerHTML() const
{
- DOMString result = "";
- for (NodeImpl *child = firstChild(); child != NULL; child = \
child->nextSibling())
- result += child->toString();
+ QString result; //Use QString to accumulate since DOMString is poor for appends
+ for (NodeImpl *child = firstChild(); child != NULL; child = \
child->nextSibling()) { + DOMString kid = child->toString();
+ result += QConstString(kid.unicode(), kid.length()).string();
+ }
return result;
}
--- branches/KDE/3.5/kdelibs/khtml/xml/dom_elementimpl.cpp #556346:556347
@ -824,17 +824,18 @
DOMString ElementImpl::toString() const
{
- DOMString result = openTagStartToString();
+ QString result = openTagStartToString().string(); //Accumulate in QString, since \
DOMString can't append well.
if (hasChildNodes()) {
result += ">";
for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
- result += child->toString();
+ DOMString kid = child->toString();
+ result += QConstString(kid.unicode(), kid.length()).string();
}
result += "</";
- result += tagName();
+ result += tagName().string();
result += ">";
} else if (result.length() == 1) {
// ensure we dont get results like < /> can happen when serialize document
--- branches/KDE/3.5/kdelibs/khtml/xml/dom_stringimpl.cpp #556346:556347
@ -416,5 +416,45 @
return QConstString(s, i).string().toInt(ok);
}
+static const unsigned short amp[] = {'&', 'a', 'm', 'p', ';'};
+static const unsigned short lt[] = {'&', 'l', 't', ';'};
+static const unsigned short gt[] = {'&', 'g', 't', ';'};
+DOMStringImpl *DOMStringImpl::escapeHTML()
+{
+ unsigned outL = 0;
+ for (unsigned int i = 0; i < l; ++i ) {
+ if ( s[i] == '&' )
+ outL += 5; //&
+ else if (s[i] == '<' || s[i] == '>')
+ outL += 4; //>/<
+ else
+ ++outL;
+ }
+ if (outL == l)
+ return this;
+
+ DOMStringImpl* toRet = new DOMStringImpl();
+ toRet->s = QT_ALLOC_QCHAR_VEC(outL);
+ toRet->l = outL;
+
+ unsigned outP = 0;
+ for (unsigned int i = 0; i < l; ++i ) {
+ if ( s[i] == '&' ) {
+ memcpy(&toRet->s[outP], amp, sizeof(amp));
+ outP += 5;
+ } else if (s[i] == '<') {
+ memcpy(&toRet->s[outP], lt, sizeof(lt));
+ outP += 4;
+ } else if (s[i] == '>') {
+ memcpy(&toRet->s[outP], gt, sizeof(gt));
+ outP += 4;
+ } else {
+ toRet->s[outP] = s[i];
+ ++outP;
+ }
+ }
+ return toRet;
+}
+
--- branches/KDE/3.5/kdelibs/khtml/xml/dom_stringimpl.h #556346:556347
@ -74,6 +74,7 @
return new DOMStringImpl(s,l);
};
+
DOMStringImpl *substring(unsigned int pos, unsigned int len);
DOMStringImpl *collapseWhiteSpace(bool preserveLF, bool preserveWS);
@ -89,6 +90,7 @
DOMStringImpl *lower() const;
DOMStringImpl *upper() const;
DOMStringImpl *capitalize(bool noFirstCap=false) const;
+ DOMStringImpl *escapeHTML();
QChar *unicode() const { return s; }
uint length() const { return l; }
--- branches/KDE/3.5/kdelibs/khtml/xml/dom_textimpl.cpp #556346:556347
@ -39,25 +39,7 @
static DOMString escapeHTML( const DOMString& in )
{
- //FIXME: this is rather slow
- DOMString s;
- for ( unsigned int i = 0; i < in.length(); ++i ) {
- switch( in[i].latin1() ) {
- case '&':
- s += "&";
- break;
- case '<':
- s += "<";
- break;
- case '>':
- s += ">";
- break;
- default:
- s += DOMString( in[i] );
- }
- }
-
- return s;
+ return in.implementation()->escapeHTML();
}
CharacterDataImpl::CharacterDataImpl(DocumentPtr *doc, DOMStringImpl* _text)
_______________________________________________
Konq-bugs mailing list
Konq-bugs@mail.kde.org
https://mail.kde.org/mailman/listinfo/konq-bugs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic