| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 static QualifiedNameCache& qualifiedNameCache() | 53 static QualifiedNameCache& qualifiedNameCache() |
| 54 { | 54 { |
| 55 // This code is lockless and thus assumes it all runs on one thread! | 55 // This code is lockless and thus assumes it all runs on one thread! |
| 56 ASSERT(isMainThread()); | 56 ASSERT(isMainThread()); |
| 57 static QualifiedNameCache* gNameCache = new QualifiedNameCache; | 57 static QualifiedNameCache* gNameCache = new QualifiedNameCache; |
| 58 return *gNameCache; | 58 return *gNameCache; |
| 59 } | 59 } |
| 60 | 60 |
| 61 struct QNameComponentsTranslator { | 61 struct QNameComponentsTranslator { |
| 62 static unsigned hash(const QualifiedNameComponents& components) | 62 static unsigned hash(const QualifiedNameData& data) |
| 63 { | 63 { |
| 64 return hashComponents(components); | 64 return hashComponents(data.m_components); |
| 65 } | 65 } |
| 66 static bool equal(QualifiedName::QualifiedNameImpl* name, const QualifiedNam
eComponents& c) | 66 static bool equal(QualifiedName::QualifiedNameImpl* name, const QualifiedNam
eData& data) |
| 67 { | 67 { |
| 68 return c.m_prefix == name->m_prefix.impl() && c.m_localName == name->m_l
ocalName.impl() && c.m_namespace == name->m_namespace.impl(); | 68 return data.m_components.m_prefix == name->m_prefix.impl() |
| 69 && data.m_components.m_localName == name->m_localName.impl() |
| 70 && data.m_components.m_namespace == name->m_namespace.impl(); |
| 69 } | 71 } |
| 70 static void translate(QualifiedName::QualifiedNameImpl*& location, const Qua
lifiedNameComponents& components, unsigned) | 72 static void translate(QualifiedName::QualifiedNameImpl*& location, const Qua
lifiedNameData& data, unsigned) |
| 71 { | 73 { |
| 72 location = QualifiedName::QualifiedNameImpl::create(AtomicString(compone
nts.m_prefix), AtomicString(components.m_localName), AtomicString(components.m_n
amespace)).leakRef(); | 74 const QualifiedNameComponents& components = data.m_components; |
| 75 location = QualifiedName::QualifiedNameImpl::create(AtomicString(compone
nts.m_prefix), AtomicString(components.m_localName), AtomicString(components.m_n
amespace), data.m_isStatic).leakRef(); |
| 73 } | 76 } |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const
AtomicString& n) | 79 QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const
AtomicString& n) |
| 77 { | 80 { |
| 78 QualifiedNameComponents components = { p.impl(), l.impl(), n.isEmpty() ? nul
lAtom.impl() : n.impl() }; | 81 QualifiedNameData data = { { p.impl(), l.impl(), n.isEmpty() ? nullAtom.impl
() : n.impl() }, false }; |
| 79 QualifiedNameCache::AddResult addResult = qualifiedNameCache().add<QNameComp
onentsTranslator>(components); | 82 QualifiedNameCache::AddResult addResult = qualifiedNameCache().add<QNameComp
onentsTranslator>(data); |
| 80 m_impl = addResult.isNewEntry ? adoptRef(*addResult.storedValue) : *addResul
t.storedValue; | 83 m_impl = addResult.isNewEntry ? adoptRef(*addResult.storedValue) : *addResul
t.storedValue; |
| 81 } | 84 } |
| 82 | 85 |
| 86 QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const
AtomicString& n, bool isStatic) |
| 87 { |
| 88 QualifiedNameData data = { { p.impl(), l.impl(), n.impl() }, isStatic }; |
| 89 QualifiedNameCache::AddResult addResult = qualifiedNameCache().add<QNameComp
onentsTranslator>(data); |
| 90 m_impl = addResult.isNewEntry ? adoptRef(*addResult.storedValue) : *addResul
t.storedValue; |
| 91 } |
| 92 |
| 83 QualifiedName::~QualifiedName() | 93 QualifiedName::~QualifiedName() |
| 84 { | 94 { |
| 85 } | 95 } |
| 86 | 96 |
| 87 QualifiedName::QualifiedNameImpl::~QualifiedNameImpl() | 97 QualifiedName::QualifiedNameImpl::~QualifiedNameImpl() |
| 88 { | 98 { |
| 89 qualifiedNameCache().remove(this); | 99 qualifiedNameCache().remove(this); |
| 90 } | 100 } |
| 91 | 101 |
| 92 String QualifiedName::toString() const | 102 String QualifiedName::toString() const |
| 93 { | 103 { |
| 94 String local = localName(); | 104 String local = localName(); |
| 95 if (hasPrefix()) | 105 if (hasPrefix()) |
| 96 return prefix().string() + ":" + local; | 106 return prefix().string() + ":" + local; |
| 97 return local; | 107 return local; |
| 98 } | 108 } |
| 99 | 109 |
| 100 // Global init routines | 110 // Global init routines |
| 101 DEFINE_GLOBAL(QualifiedName, anyName, nullAtom, starAtom, starAtom) | 111 DEFINE_GLOBAL(QualifiedName, anyName, nullAtom, starAtom, starAtom) |
| 102 | 112 |
| 103 void QualifiedName::init() | 113 void QualifiedName::init() |
| 104 { | 114 { |
| 105 ASSERT(starAtom.impl()); | 115 ASSERT(starAtom.impl()); |
| 106 new ((void*)&anyName) QualifiedName(nullAtom, starAtom, starAtom); | 116 new ((void*)&anyName) QualifiedName(nullAtom, starAtom, starAtom, true ); |
| 107 } | 117 } |
| 108 | 118 |
| 109 const QualifiedName& nullQName() | 119 const QualifiedName& QualifiedName::null() |
| 110 { | 120 { |
| 111 DEFINE_STATIC_LOCAL(QualifiedName, nullName, (nullAtom, nullAtom, nullAtom))
; | 121 DEFINE_STATIC_LOCAL(QualifiedName, nullName, (nullAtom, nullAtom, nullAtom,
true)); |
| 112 return nullName; | 122 return nullName; |
| 113 } | 123 } |
| 114 | 124 |
| 115 const AtomicString& QualifiedName::localNameUpper() const | 125 const AtomicString& QualifiedName::localNameUpper() const |
| 116 { | 126 { |
| 117 if (!m_impl->m_localNameUpper) | 127 if (!m_impl->m_localNameUpper) |
| 118 m_impl->m_localNameUpper = m_impl->m_localName.upper(); | 128 m_impl->m_localNameUpper = m_impl->m_localName.upper(); |
| 119 return m_impl->m_localNameUpper; | 129 return m_impl->m_localNameUpper; |
| 120 } | 130 } |
| 121 | 131 |
| 122 unsigned QualifiedName::QualifiedNameImpl::computeHash() const | 132 unsigned QualifiedName::QualifiedNameImpl::computeHash() const |
| 123 { | 133 { |
| 124 QualifiedNameComponents components = { m_prefix.impl(), m_localName.impl(),
m_namespace.impl() }; | 134 QualifiedNameComponents components = { m_prefix.impl(), m_localName.impl(),
m_namespace.impl() }; |
| 125 return hashComponents(components); | 135 return hashComponents(components); |
| 126 } | 136 } |
| 127 | 137 |
| 128 void createQualifiedName(void* targetAddress, StringImpl* name, const AtomicStri
ng& nameNamespace) | 138 void QualifiedName::createStatic(void* targetAddress, StringImpl* name, const At
omicString& nameNamespace) |
| 129 { | 139 { |
| 130 new (targetAddress) QualifiedName(nullAtom, AtomicString(name), nameNamespac
e); | 140 new (targetAddress) QualifiedName(nullAtom, AtomicString(name), nameNamespac
e, true); |
| 131 } | 141 } |
| 132 | 142 |
| 133 void createQualifiedName(void* targetAddress, StringImpl* name) | 143 void QualifiedName::createStatic(void* targetAddress, StringImpl* name) |
| 134 { | 144 { |
| 135 new (targetAddress) QualifiedName(nullAtom, AtomicString(name), nullAtom); | 145 new (targetAddress) QualifiedName(nullAtom, AtomicString(name), nullAtom, tr
ue); |
| 136 } | 146 } |
| 137 | 147 |
| 138 } | 148 } |
| OLD | NEW |