[webkit-dev] Null value for QualifiedName
Ryosuke Niwa
rniwa at webkit.org
Tue Aug 24 11:35:15 PDT 2010
Greetings all,
While working on the bug 44288<https://bugs.webkit.org/show_bug.cgi?id=44288>,
it came to my attention that
the default constructor of QualifiedName is behind a
flag QNAME_DEFAULT_CONSTRUCTOR,
and I can't find a qualified name that stands for invalid / null value.
Is there any designated qualified name object that stands for invalid / null
value?
Invalid / null qualified name will be useful in the context like:
http://trac.webkit.org/browser/trunk/WebCore/editing/markup.cpp?rev=65854#L488
:
void MarkupAccumulator::appendText(Vector<UChar>& out, Text* text)
{
const QualifiedName* parentName = 0;
if (text->parentElement())
parentName =
&static_cast<Element*>(text->parentElement())->tagQName();
if (parentName && (*parentName == scriptTag || *parentName == styleTag
|| *parentName == xmpTag)) {
appendUCharRange(out, ucharRange(text, m_range));
return;
}
if (!shouldAnnotate() || (parentName && *parentName == textareaTag)) {
appendEscapedContent(out, ucharRange(text, m_range),
text->document()->isHTMLDocument());
return;
}
...
where I obtain the qualified name of the parent element which may or may not
exist.
If we had a null qualified name, above code can be re-written as:
void MarkupAccumulator::appendText(Vector<UChar>& out, Text* text)
{
QualifiedName parentName = nullName;
if (text->parentElement())
parentName =
&static_cast<Element*>(text->parentElement())->tagQName();
if (parentName == scriptTag || parentName == styleTag || parentName ==
xmpTag) {
appendUCharRange(out, ucharRange(text, m_range));
return;
}
if (!shouldAnnotate() || parentName == textareaTag) {
appendEscapedContent(out, ucharRange(text, m_range),
text->document()->isHTMLDocument());
return;
}
...
IMHO, new code is easier to read and has very little drawbacks (possible
slowdown use to construction of QualifiedName).
I could have used htmlTag or any other qualified name different from the
four names used above,
but that wouldn't be semantically correct.
Ryosuke Niwa
Software Engineer
Google Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20100824/85c6a9b5/attachment.html>
More information about the webkit-dev
mailing list