Changeset 152337 in webkit


Ignore:
Timestamp:
Jul 2, 2013 10:07:45 PM (11 years ago)
Author:
rniwa@webkit.org
Message:

Modernize QualifiedName by wrapping gNameCache in a function and using more early exits
https://bugs.webkit.org/show_bug.cgi?id=118299

Reviewed by Andreas Kling.

Did cleanups.

  • dom/QualifiedName.cpp:

(WebCore::qualifiedNameCache): Added to wrap gNameCache.
(WebCore::QualifiedName::QualifiedName):
(WebCore::QualifiedName::QualifiedNameImpl::~QualifiedNameImpl):
(WebCore::QualifiedName::toString): Use early exit and StringBuilder.
(WebCore::QualifiedName::init): Use early exit.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r152335 r152337  
     12013-07-02  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Modernize QualifiedName by wrapping gNameCache in a function and using more early exits
     4        https://bugs.webkit.org/show_bug.cgi?id=118299
     5
     6        Reviewed by Andreas Kling.
     7
     8        Did cleanups.
     9
     10        * dom/QualifiedName.cpp:
     11        (WebCore::qualifiedNameCache): Added to wrap gNameCache.
     12        (WebCore::QualifiedName::QualifiedName):
     13        (WebCore::QualifiedName::QualifiedNameImpl::~QualifiedNameImpl):
     14        (WebCore::QualifiedName::toString): Use early exit and StringBuilder.
     15        (WebCore::QualifiedName::init): Use early exit.
     16
    1172013-07-02  Simon Fraser  <simon.fraser@apple.com>
    218
  • trunk/Source/WebCore/dom/QualifiedName.cpp

    r151800 r152337  
    3434#include <wtf/HashSet.h>
    3535#include <wtf/StaticConstructors.h>
     36#include <wtf/text/StringBuilder.h>
    3637
    3738#if ENABLE(MATHML)
     
    7778};
    7879
    79 static QNameSet* gNameCache;
     80static inline QNameSet& qualifiedNameCache()
     81{
     82    DEFINE_STATIC_LOCAL(QNameSet, nameCache, ());
     83    return nameCache;
     84}
    8085
    8186QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const AtomicString& n)
    8287{
    83     if (!gNameCache)
    84         gNameCache = new QNameSet;
    8588    QualifiedNameComponents components = { p.impl(), l.impl(), n.isEmpty() ? nullAtom.impl() : n.impl() };
    86     QNameSet::AddResult addResult = gNameCache->add<QNameComponentsTranslator>(components);
     89    QNameSet::AddResult addResult = qualifiedNameCache().add<QNameComponentsTranslator>(components);
    8790    m_impl = *addResult.iterator;
    8891    if (!addResult.isNewEntry)
     
    107110QualifiedName::QualifiedNameImpl::~QualifiedNameImpl()
    108111{
    109     gNameCache->remove(this);
     112    qualifiedNameCache().remove(this);
    110113}
    111114
    112115String QualifiedName::toString() const
    113116{
    114     String local = localName();
    115     if (hasPrefix()) {
    116         String result = prefix().string();
    117         result.append(":");
    118         result.append(local);
    119         return result;
    120     }
    121     return local;
     117    if (!hasPrefix())
     118        return localName();
     119
     120    StringBuilder result;
     121    result.append(prefix());
     122    result.append(':');
     123    result.append(localName());
     124    return result.toString();
    122125}
    123126
     
    127130void QualifiedName::init()
    128131{
    129     static bool initialized;
    130     if (!initialized) {
    131         // Use placement new to initialize the globals.
    132        
    133         AtomicString::init();
    134         new (NotNull, (void*)&anyName) QualifiedName(nullAtom, starAtom, starAtom);
    135         initialized = true;
    136     }
     132    static bool initialized = false;
     133    if (initialized)
     134        return;
     135
     136    // Use placement new to initialize the globals.
     137    AtomicString::init();
     138    new (NotNull, (void*)&anyName) QualifiedName(nullAtom, starAtom, starAtom);
     139    initialized = true;
    137140}
    138141
Note: See TracChangeset for help on using the changeset viewer.