Commit 3ae50982 authored by rjw's avatar rjw

Optimizations that remove unnecessary cfstring allocations of local scope

        strings.  QString::gstring_toQString and QString::gstring_toCFString were
        added to simplify the reuse of a static CFString as the backing store for
        local QStrings.  Hit the top two problem areas.  Many more gains to be had
        by using this technique.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@747 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0033926d
2002-03-15 Richard Williamson <rjw@apple.com>
Optimizations that remove unnecessary cfstring allocations of local scope
strings. QString::gstring_toQString and QString::gstring_toCFString were
added to simplify the reuse of a static CFString as the backing store for
local QStrings. Hit the top two problem areas. Many more gains to be had
by using this technique.
* src/kdelibs/khtml/css/cssstyleselector.cpp:
(CSSStyleSelector::checkOneSelector):
* src/kdelibs/khtml/rendering/render_text.cpp: (RenderText::calcMinMaxWidth):
* src/kwq/KWQString.mm: (QString::gstring_toQString),
(QString::gstring_toCFString):
* src/kwq/qt/qstring.h:
2002-03-14 Richard Williamson <rjw@apple.com>
Fixed another problem in QString::find().
......
2002-03-15 Richard Williamson <rjw@apple.com>
Optimizations that remove unnecessary cfstring allocations of local scope
strings. QString::gstring_toQString and QString::gstring_toCFString were
added to simplify the reuse of a static CFString as the backing store for
local QStrings. Hit the top two problem areas. Many more gains to be had
by using this technique.
* src/kdelibs/khtml/css/cssstyleselector.cpp:
(CSSStyleSelector::checkOneSelector):
* src/kdelibs/khtml/rendering/render_text.cpp: (RenderText::calcMinMaxWidth):
* src/kwq/KWQString.mm: (QString::gstring_toQString),
(QString::gstring_toCFString):
* src/kwq/qt/qstring.h:
2002-03-14 Richard Williamson <rjw@apple.com>
Fixed another problem in QString::find().
......
2002-03-15 Richard Williamson <rjw@apple.com>
Optimizations that remove unnecessary cfstring allocations of local scope
strings. QString::gstring_toQString and QString::gstring_toCFString were
added to simplify the reuse of a static CFString as the backing store for
local QStrings. Hit the top two problem areas. Many more gains to be had
by using this technique.
* src/kdelibs/khtml/css/cssstyleselector.cpp:
(CSSStyleSelector::checkOneSelector):
* src/kdelibs/khtml/rendering/render_text.cpp: (RenderText::calcMinMaxWidth):
* src/kwq/KWQString.mm: (QString::gstring_toQString),
(QString::gstring_toCFString):
* src/kwq/qt/qstring.h:
2002-03-14 Richard Williamson <rjw@apple.com>
Fixed another problem in QString::find().
......
......@@ -470,6 +470,13 @@ static void checkPseudoState( DOM::ElementImpl *e )
pseudoState = KHTMLFactory::vLinks()->contains( u ) ? PseudoVisited : PseudoLink;
}
#ifdef APPLE_CHANGES
#define OPTIMIZE_STRING_USAGE
#ifdef OPTIMIZE_STRING_USAGE
static CFMutableStringRef reuseableString = 0;
#endif
#endif
bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl *e)
{
......@@ -523,9 +530,13 @@ bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl
}
if(sel->match == CSSSelector::Pseudo)
{
#if (defined(APPLE_CHANGES) && defined(OPTIMIZE_STRING_USAGE))
const QString value = QString::gstring_toQString(&reuseableString, (UniChar *)(sel->value.unicode()), sel->value.length());
#else
// Pseudo elements. We need to check first child here. No dynamic pseudo
// elements for the moment
const QString& value = sel->value.string();
#endif
//kdDebug() << "CSSOrderedRule::pseudo " << value << endl;
if(value == "first-child") {
// first-child matches the first child that is an element!
......
......@@ -694,11 +694,7 @@ void RenderText::calcMinMaxWidth()
if (wordlen)
{
#if (defined(APPLE_CHANGES) && defined(OPTIMIZE_STRING_USAGE))
if (reuseableString == 0)
reuseableString = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocatorDefault, (UniChar *)(str->s+i), wordlen, wordlen, kCFAllocatorDefault);
else
CFStringSetExternalCharactersNoCopy (reuseableString, (UniChar *)(str->s+i), wordlen, wordlen);
int w = _fm._width(reuseableString);
int w = _fm._width(QString::gstring_toCFString(&reuseableString, (UniChar *)(str->s+i), wordlen));
#else
int w = _fm.width(QConstString(str->s+i, wordlen).string());
#endif
......
......@@ -351,6 +351,9 @@ public:
static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFMutableString(CFMutableStringRef);
static QString fromCFString(CFStringRef);
static QString gstring_toQString(CFMutableStringRef *ref, UniChar *uchars, int len);
static CFMutableStringRef gstring_toCFString(CFMutableStringRef *ref, UniChar *uchars, int len);
// constructors, copy constructors, and destructors ------------------------
......
......@@ -171,6 +171,24 @@ QString QString::fromCFString(CFStringRef cfs)
return qs;
}
QString QString::gstring_toQString(CFMutableStringRef *ref, UniChar *uchars, int len){
if (*ref == 0)
*ref = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocatorDefault, uchars, len, len, kCFAllocatorDefault);
else
CFStringSetExternalCharactersNoCopy (*ref, uchars, len, len);
return QString::fromCFMutableString(*ref);
}
CFMutableStringRef QString::gstring_toCFString(CFMutableStringRef *ref, UniChar *uchars, int len)
{
if (*ref == 0)
*ref = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocatorDefault, uchars, len, len, kCFAllocatorDefault);
else
CFStringSetExternalCharactersNoCopy (*ref, uchars, len, len);
return *ref;
}
// constructors, copy constructors, and destructors ----------------------------
......
......@@ -351,6 +351,9 @@ public:
static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFMutableString(CFMutableStringRef);
static QString fromCFString(CFStringRef);
static QString gstring_toQString(CFMutableStringRef *ref, UniChar *uchars, int len);
static CFMutableStringRef gstring_toCFString(CFMutableStringRef *ref, UniChar *uchars, int len);
// constructors, copy constructors, and destructors ------------------------
......
......@@ -470,6 +470,13 @@ static void checkPseudoState( DOM::ElementImpl *e )
pseudoState = KHTMLFactory::vLinks()->contains( u ) ? PseudoVisited : PseudoLink;
}
#ifdef APPLE_CHANGES
#define OPTIMIZE_STRING_USAGE
#ifdef OPTIMIZE_STRING_USAGE
static CFMutableStringRef reuseableString = 0;
#endif
#endif
bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl *e)
{
......@@ -523,9 +530,13 @@ bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl
}
if(sel->match == CSSSelector::Pseudo)
{
#if (defined(APPLE_CHANGES) && defined(OPTIMIZE_STRING_USAGE))
const QString value = QString::gstring_toQString(&reuseableString, (UniChar *)(sel->value.unicode()), sel->value.length());
#else
// Pseudo elements. We need to check first child here. No dynamic pseudo
// elements for the moment
const QString& value = sel->value.string();
#endif
//kdDebug() << "CSSOrderedRule::pseudo " << value << endl;
if(value == "first-child") {
// first-child matches the first child that is an element!
......
......@@ -694,11 +694,7 @@ void RenderText::calcMinMaxWidth()
if (wordlen)
{
#if (defined(APPLE_CHANGES) && defined(OPTIMIZE_STRING_USAGE))
if (reuseableString == 0)
reuseableString = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocatorDefault, (UniChar *)(str->s+i), wordlen, wordlen, kCFAllocatorDefault);
else
CFStringSetExternalCharactersNoCopy (reuseableString, (UniChar *)(str->s+i), wordlen, wordlen);
int w = _fm._width(reuseableString);
int w = _fm._width(QString::gstring_toCFString(&reuseableString, (UniChar *)(str->s+i), wordlen));
#else
int w = _fm.width(QConstString(str->s+i, wordlen).string());
#endif
......
......@@ -171,6 +171,24 @@ QString QString::fromCFString(CFStringRef cfs)
return qs;
}
QString QString::gstring_toQString(CFMutableStringRef *ref, UniChar *uchars, int len){
if (*ref == 0)
*ref = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocatorDefault, uchars, len, len, kCFAllocatorDefault);
else
CFStringSetExternalCharactersNoCopy (*ref, uchars, len, len);
return QString::fromCFMutableString(*ref);
}
CFMutableStringRef QString::gstring_toCFString(CFMutableStringRef *ref, UniChar *uchars, int len)
{
if (*ref == 0)
*ref = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocatorDefault, uchars, len, len, kCFAllocatorDefault);
else
CFStringSetExternalCharactersNoCopy (*ref, uchars, len, len);
return *ref;
}
// constructors, copy constructors, and destructors ----------------------------
......
......@@ -351,6 +351,9 @@ public:
static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFMutableString(CFMutableStringRef);
static QString fromCFString(CFStringRef);
static QString gstring_toQString(CFMutableStringRef *ref, UniChar *uchars, int len);
static CFMutableStringRef gstring_toCFString(CFMutableStringRef *ref, UniChar *uchars, int len);
// constructors, copy constructors, and destructors ------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment