| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/html/parser/CompactHTMLToken.h" | 27 #include "core/html/parser/CompactHTMLToken.h" |
| 28 | 28 |
| 29 #include "core/dom/QualifiedName.h" | 29 #include "core/dom/QualifiedName.h" |
| 30 #include "core/html/parser/HTMLParserIdioms.h" | 30 #include "core/html/parser/HTMLParserIdioms.h" |
| 31 | 31 |
| 32 namespace WebCore { | 32 namespace WebCore { |
| 33 | 33 |
| 34 struct SameSizeAsCompactHTMLToken { | 34 struct SameSizeAsCompactHTMLToken { |
| 35 unsigned bitfields; | 35 unsigned bitfields; |
| 36 HTMLIdentifier data; | 36 String data; |
| 37 Vector<Attribute> vector; | 37 Vector<Attribute> vector; |
| 38 TextPosition textPosition; | 38 TextPosition textPosition; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), C
ompactHTMLToken_should_stay_small); | 41 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), C
ompactHTMLToken_should_stay_small); |
| 42 | 42 |
| 43 CompactHTMLToken::CompactHTMLToken(const HTMLToken* token, const TextPosition& t
extPosition) | 43 CompactHTMLToken::CompactHTMLToken(const HTMLToken* token, const TextPosition& t
extPosition) |
| 44 : m_type(token->type()) | 44 : m_type(token->type()) |
| 45 , m_isAll8BitData(false) | 45 , m_isAll8BitData(false) |
| 46 , m_doctypeForcesQuirks(false) | 46 , m_doctypeForcesQuirks(false) |
| 47 , m_textPosition(textPosition) | 47 , m_textPosition(textPosition) |
| 48 { | 48 { |
| 49 switch (m_type) { | 49 switch (m_type) { |
| 50 case HTMLToken::Uninitialized: | 50 case HTMLToken::Uninitialized: |
| 51 ASSERT_NOT_REACHED(); | 51 ASSERT_NOT_REACHED(); |
| 52 break; | 52 break; |
| 53 case HTMLToken::DOCTYPE: { | 53 case HTMLToken::DOCTYPE: { |
| 54 m_data = HTMLIdentifier(token->name(), Likely8Bit); | 54 m_data = createAtomizedString(token->name(), Likely8Bit); |
| 55 |
| 55 // There is only 1 DOCTYPE token per document, so to avoid increasing th
e | 56 // There is only 1 DOCTYPE token per document, so to avoid increasing th
e |
| 56 // size of CompactHTMLToken, we just use the m_attributes vector. | 57 // size of CompactHTMLToken, we just use the m_attributes vector. |
| 57 m_attributes.append(Attribute(HTMLIdentifier(token->publicIdentifier(),
Likely8Bit), String(token->systemIdentifier()))); | 58 m_attributes.append(Attribute(createAtomizedString(token->publicIdentifi
er(), Likely8Bit), String(token->systemIdentifier()))); |
| 58 m_doctypeForcesQuirks = token->forceQuirks(); | 59 m_doctypeForcesQuirks = token->forceQuirks(); |
| 59 break; | 60 break; |
| 60 } | 61 } |
| 61 case HTMLToken::EndOfFile: | 62 case HTMLToken::EndOfFile: |
| 62 break; | 63 break; |
| 63 case HTMLToken::StartTag: | 64 case HTMLToken::StartTag: |
| 64 m_attributes.reserveInitialCapacity(token->attributes().size()); | 65 m_attributes.reserveInitialCapacity(token->attributes().size()); |
| 65 for (Vector<HTMLToken::Attribute>::const_iterator it = token->attributes
().begin(); it != token->attributes().end(); ++it) | 66 for (Vector<HTMLToken::Attribute>::const_iterator it = token->attributes
().begin(); it != token->attributes().end(); ++it) |
| 66 m_attributes.append(Attribute(HTMLIdentifier(it->name, Likely8Bit),
StringImpl::create8BitIfPossible(it->value))); | 67 m_attributes.append(Attribute(createAtomizedString(it->name, Likely8
Bit), StringImpl::create8BitIfPossible(it->value))); |
| 67 // Fall through! | 68 // Fall through! |
| 68 case HTMLToken::EndTag: | 69 case HTMLToken::EndTag: |
| 69 m_selfClosing = token->selfClosing(); | 70 m_selfClosing = token->selfClosing(); |
| 70 // Fall through! | 71 // Fall through! |
| 71 case HTMLToken::Comment: | 72 case HTMLToken::Comment: |
| 72 case HTMLToken::Character: { | 73 case HTMLToken::Character: { |
| 73 m_isAll8BitData = token->isAll8BitData(); | 74 m_isAll8BitData = token->isAll8BitData(); |
| 74 m_data = HTMLIdentifier(token->data(), token->isAll8BitData() ? Force8Bi
t : Force16Bit); | 75 m_data = createAtomizedString(token->data(), token->isAll8BitData() ? Fo
rce8Bit : Force16Bit); |
| 75 break; | 76 break; |
| 76 } | 77 } |
| 77 default: | 78 default: |
| 78 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
| 79 break; | 80 break; |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const Qual
ifiedName& name) const | 84 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const Qual
ifiedName& name) const |
| 84 { | 85 { |
| 85 for (unsigned i = 0; i < m_attributes.size(); ++i) { | 86 for (unsigned i = 0; i < m_attributes.size(); ++i) { |
| 86 if (threadSafeMatch(m_attributes.at(i).name, name)) | 87 if (threadSafeMatch(m_attributes.at(i).name, name)) |
| 87 return &m_attributes.at(i); | 88 return &m_attributes.at(i); |
| 88 } | 89 } |
| 89 return 0; | 90 return 0; |
| 90 } | 91 } |
| 91 | 92 |
| 92 bool CompactHTMLToken::isSafeToSendToAnotherThread() const | 93 bool CompactHTMLToken::isSafeToSendToAnotherThread() const |
| 93 { | 94 { |
| 94 for (Vector<Attribute>::const_iterator it = m_attributes.begin(); it != m_at
tributes.end(); ++it) { | 95 for (Vector<Attribute>::const_iterator it = m_attributes.begin(); it != m_at
tributes.end(); ++it) { |
| 95 if (!it->name.isSafeToSendToAnotherThread()) | 96 if (!it->name.isSafeToSendToAnotherThread()) |
| 96 return false; | 97 return false; |
| 97 if (!it->value.isSafeToSendToAnotherThread()) | 98 if (!it->value.isSafeToSendToAnotherThread()) |
| 98 return false; | 99 return false; |
| 99 } | 100 } |
| 100 return m_data.isSafeToSendToAnotherThread(); | 101 return m_data.isSafeToSendToAnotherThread(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 } | 104 } |
| OLD | NEW |