2 * Copyright (C) 2013 Google, Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "core/html/parser/CompactHTMLToken.h"
29 #include "core/dom/QualifiedName.h"
30 #include "core/html/parser/HTMLParserIdioms.h"
34 struct SameSizeAsCompactHTMLToken {
37 Vector<Attribute> vector;
38 TextPosition textPosition;
41 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), CompactHTMLToken_should_stay_small);
43 CompactHTMLToken::CompactHTMLToken(const HTMLToken* token, const TextPosition& textPosition)
44 : m_type(token->type())
45 , m_isAll8BitData(false)
46 , m_doctypeForcesQuirks(false)
47 , m_textPosition(textPosition)
50 case HTMLToken::Uninitialized:
53 case HTMLToken::DOCTYPE: {
54 m_data = attemptStaticStringCreation(token->name(), Likely8Bit);
56 // There is only 1 DOCTYPE token per document, so to avoid increasing the
57 // size of CompactHTMLToken, we just use the m_attributes vector.
58 m_attributes.append(Attribute(attemptStaticStringCreation(token->publicIdentifier(), Likely8Bit), String(token->systemIdentifier())));
59 m_doctypeForcesQuirks = token->forceQuirks();
62 case HTMLToken::EndOfFile:
64 case HTMLToken::StartTag:
65 m_attributes.reserveInitialCapacity(token->attributes().size());
66 for (Vector<HTMLToken::Attribute>::const_iterator it = token->attributes().begin(); it != token->attributes().end(); ++it)
67 m_attributes.append(Attribute(attemptStaticStringCreation(it->name, Likely8Bit), StringImpl::create8BitIfPossible(it->value)));
69 case HTMLToken::EndTag:
70 m_selfClosing = token->selfClosing();
72 case HTMLToken::Comment:
73 case HTMLToken::Character: {
74 m_isAll8BitData = token->isAll8BitData();
75 m_data = attemptStaticStringCreation(token->data(), token->isAll8BitData() ? Force8Bit : Force16Bit);
84 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const QualifiedName& name) const
86 for (unsigned i = 0; i < m_attributes.size(); ++i) {
87 if (threadSafeMatch(m_attributes.at(i).name, name))
88 return &m_attributes.at(i);
93 bool CompactHTMLToken::isSafeToSendToAnotherThread() const
95 for (Vector<Attribute>::const_iterator it = m_attributes.begin(); it != m_attributes.end(); ++it) {
96 if (!it->name.isSafeToSendToAnotherThread())
98 if (!it->value.isSafeToSendToAnotherThread())
101 return m_data.isSafeToSendToAnotherThread();