/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * Storage of the children and attributes of a DOM node; storage for * the two is unified to minimize footprint.
*/
const nsAttrValue* AttrArray::GetAttr(const nsAtom* aLocalName) const {
NS_ASSERTION(aLocalName, "Must have attr name"); for (const InternalAttr& attr : Attrs()) { if (attr.mName.Equals(aLocalName)) { return &attr.mValue;
}
} return nullptr;
}
const nsAttrValue* AttrArray::GetAttr(const nsAtom* aLocalName,
int32_t aNamespaceID) const {
NS_ASSERTION(aLocalName, "Must have attr name");
NS_ASSERTION(aNamespaceID != kNameSpaceID_Unknown, "Must have namespace"); if (aNamespaceID == kNameSpaceID_None) { // This should be the common case so lets use the optimized loop return GetAttr(aLocalName);
} for (const InternalAttr& attr : Attrs()) { if (attr.mName.Equals(aLocalName, aNamespaceID)) { return &attr.mValue;
}
} return nullptr;
}
const nsAttrValue* AttrArray::GetAttr(const nsAString& aName,
nsCaseTreatment aCaseSensitive) const { // Check whether someone is being silly and passing non-lowercase // attr names. if (aCaseSensitive == eIgnoreCase &&
nsContentUtils::StringContainsASCIIUpper(aName)) { // Try again with a lowercased name, but make sure we can't reenter this // block by passing eCaseSensitive for aCaseSensitive.
nsAutoString lowercase;
nsContentUtils::ASCIIToLower(aName, lowercase); return GetAttr(lowercase, eCaseMatters);
}
for (const InternalAttr& attr : Attrs()) { if (attr.mName.QualifiedNameEquals(aName)) { return &attr.mValue;
}
}
// InternalAttr are not trivially copyable *but* we manually called the // destructor so the memmove should be ok.
memmove((void*)(mImpl->mBuffer + aPos), mImpl->mBuffer + aPos + 1,
(mImpl->mAttrCount - aPos - 1) * sizeof(InternalAttr));
int32_t AttrArray::IndexOfAttr(const nsAtom* aLocalName) const {
int32_t i = 0; for (const InternalAttr& attr : Attrs()) { if (attr.mName.Equals(aLocalName)) { return i;
}
++i;
} return -1;
}
int32_t AttrArray::IndexOfAttr(const nsAtom* aLocalName,
int32_t aNamespaceID) const { if (aNamespaceID == kNameSpaceID_None) { // This should be the common case so lets use the optimized loop return IndexOfAttr(aLocalName);
}
int32_t i = 0; for (const InternalAttr& attr : Attrs()) { if (attr.mName.Equals(aLocalName, aNamespaceID)) { return i;
}
++i;
} return -1;
}
void AttrArray::Compact() { if (!mImpl) { return;
}
if (!mImpl->mAttrCount && !mImpl->mMappedAttributeBits) {
mImpl.reset(); return;
}
// Nothing to do. if (mImpl->mAttrCount == mImpl->mCapacity) { return;
}
nsresult AttrArray::EnsureCapacityToClone(const AttrArray& aOther) {
MOZ_ASSERT(!mImpl, "AttrArray::EnsureCapacityToClone requires the array be empty " "when called");
uint32_t attrCount = aOther.AttrCount(); if (!attrCount) { return NS_OK;
}
// No need to use a CheckedUint32 because we are cloning. We know that we // have already allocated an AttrArray of this size.
mImpl.reset( static_cast<Impl*>(malloc(Impl::AllocationSizeForAttributes(attrCount))));
NS_ENSURE_TRUE(mImpl, NS_ERROR_OUT_OF_MEMORY);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.