1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/*
* Copyright (C) 2005, 2006, 2009 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "QualifiedName.h"
#include "CommonAtomStrings.h"
#include "Namespace.h"
#include "NodeName.h"
#include "QualifiedNameCache.h"
#include "ThreadGlobalData.h"
#include <wtf/Assertions.h>
namespace WebCore {
DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(QualifiedName);
DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(QualifiedNameQualifiedNameImpl);
QualifiedName::QualifiedNameImpl::QualifiedNameImpl(const AtomString& prefix, const AtomString& localName, const AtomString& namespaceURI)
: m_namespace(Namespace::Unknown)
, m_nodeName(NodeName::Unknown)
, m_prefix(prefix)
, m_localName(localName)
, m_namespaceURI(namespaceURI)
{
ASSERT(!namespaceURI.isEmpty() || namespaceURI.isNull());
}
static QualifiedNameComponents makeComponents(const AtomString& prefix, const AtomString& localName, const AtomString& namespaceURI)
{
return { prefix.impl(), localName.impl(), namespaceURI.isEmpty() ? nullptr : namespaceURI.impl() };
}
QualifiedName::QualifiedName(const AtomString& prefix, const AtomString& localName, const AtomString& namespaceURI)
: m_impl(threadGlobalData().qualifiedNameCache().getOrCreate(makeComponents(prefix, localName, namespaceURI)))
{
}
QualifiedName::QualifiedName(const AtomString& prefix, const AtomString& localName, const AtomString& namespaceURI, Namespace nodeNamespace, NodeName nodeName)
: m_impl(threadGlobalData().qualifiedNameCache().getOrCreate(makeComponents(prefix, localName, namespaceURI), nodeNamespace, nodeName))
{
}
QualifiedName::QualifiedNameImpl::~QualifiedNameImpl()
{
threadGlobalData().qualifiedNameCache().remove(*this);
}
// Global init routines
LazyNeverDestroyed<const QualifiedName> anyName;
LazyNeverDestroyed<const QualifiedName> nullName;
void QualifiedName::init()
{
static bool initialized = false;
if (initialized)
return;
anyName.construct(nullAtom(), starAtom(), starAtom(), Namespace::Unknown, NodeName::Unknown);
nullName.construct(nullAtom(), nullAtom(), nullAtom(), Namespace::None, NodeName::Unknown);
initialized = true;
}
const AtomString& QualifiedName::localNameUppercase() const
{
if (!m_impl->m_localNameUpper)
m_impl->m_localNameUpper = m_impl->m_localName.convertToASCIIUppercase();
return m_impl->m_localNameUpper;
}
unsigned QualifiedName::QualifiedNameImpl::computeHash() const
{
QualifiedNameComponents components = { m_prefix.impl(), m_localName.impl(), m_namespaceURI.impl() };
return WTF::computeHash(components);
}
}
|