| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 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. | |
| 12 * | |
| 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. | |
| 24 */ | |
| 25 | |
| 26 #include "sky/engine/core/html/parser/CompactHTMLToken.h" | |
| 27 | |
| 28 #include "sky/engine/core/dom/QualifiedName.h" | |
| 29 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" | |
| 30 | |
| 31 namespace blink { | |
| 32 | |
| 33 struct SameSizeAsCompactHTMLToken { | |
| 34 unsigned bitfields; | |
| 35 String data; | |
| 36 Vector<Attribute> vector; | |
| 37 TextPosition textPosition; | |
| 38 }; | |
| 39 | |
| 40 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), C
ompactHTMLToken_should_stay_small); | |
| 41 | |
| 42 CompactHTMLToken::CompactHTMLToken(const HTMLToken* token, const TextPosition& t
extPosition) | |
| 43 : m_type(token->type()) | |
| 44 , m_isAll8BitData(false) | |
| 45 , m_textPosition(textPosition) | |
| 46 { | |
| 47 switch (m_type) { | |
| 48 case HTMLToken::Uninitialized: | |
| 49 ASSERT_NOT_REACHED(); | |
| 50 break; | |
| 51 case HTMLToken::EndOfFile: | |
| 52 break; | |
| 53 case HTMLToken::StartTag: | |
| 54 m_attributes.reserveInitialCapacity(token->attributes().size()); | |
| 55 for (Vector<HTMLToken::Attribute>::const_iterator it = token->attributes
().begin(); it != token->attributes().end(); ++it) | |
| 56 m_attributes.append(Attribute(attemptStaticStringCreation(it->name,
Likely8Bit), StringImpl::create8BitIfPossible(it->value))); | |
| 57 // Fall through! | |
| 58 case HTMLToken::EndTag: | |
| 59 m_selfClosing = token->selfClosing(); | |
| 60 // Fall through! | |
| 61 case HTMLToken::Character: { | |
| 62 m_isAll8BitData = token->isAll8BitData(); | |
| 63 m_data = attemptStaticStringCreation(token->data(), token->isAll8BitData
() ? Force8Bit : Force16Bit); | |
| 64 break; | |
| 65 } | |
| 66 default: | |
| 67 ASSERT_NOT_REACHED(); | |
| 68 break; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const Qual
ifiedName& name) const | |
| 73 { | |
| 74 for (unsigned i = 0; i < m_attributes.size(); ++i) { | |
| 75 if (threadSafeMatch(m_attributes.at(i).name, name)) | |
| 76 return &m_attributes.at(i); | |
| 77 } | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 bool CompactHTMLToken::isSafeToSendToAnotherThread() const | |
| 82 { | |
| 83 for (Vector<Attribute>::const_iterator it = m_attributes.begin(); it != m_at
tributes.end(); ++it) { | |
| 84 if (!it->name.isSafeToSendToAnotherThread()) | |
| 85 return false; | |
| 86 if (!it->value.isSafeToSendToAnotherThread()) | |
| 87 return false; | |
| 88 } | |
| 89 return m_data.isSafeToSendToAnotherThread(); | |
| 90 } | |
| 91 | |
| 92 } | |
| OLD | NEW |