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