| Differences between
and this patch
- a/Source/WebCore/ChangeLog +34 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2013-01-18  Adam Barth  <abarth@webkit.org>
2
3
        BackgroundHTMLParser should be able to atomize well-known strings
4
        https://bugs.webkit.org/show_bug.cgi?id=107337
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        No new tests (OOPS!).
9
10
        * WebCore.gypi:
11
        * html/parser/BackgroundHTMLParser.cpp:
12
        (WebCore::BackgroundHTMLParser::pumpTokenizer):
13
        * html/parser/CompactHTMLToken.cpp:
14
        (WebCore::CompactHTMLToken::CompactHTMLToken):
15
        (WebCore::CompactHTMLToken::isSafeToSendToAnotherThread):
16
        * html/parser/CompactHTMLToken.h:
17
        (WebCore::CompactHTMLToken::data):
18
        (CompactHTMLToken):
19
        * html/parser/HTMLDocumentParser.cpp:
20
        (WebCore::HTMLDocumentParser::startBackgroundParser):
21
        * html/parser/HTMLIdentifier.cpp: Added.
22
        (WebCore):
23
        (WebCore::identifierTable):
24
        (WebCore::findIndex):
25
        (WebCore::HTMLIdentifier::HTMLIdentifier):
26
        (WebCore::asString):
27
        (WebCore::HTMLIdentifier::init):
28
        * html/parser/HTMLIdentifier.h: Copied from Source/WebCore/html/parser/CompactHTMLToken.h.
29
        (WebCore):
30
        (HTMLIdentifier):
31
        (WebCore::HTMLIdentifier::HTMLIdentifier):
32
        * html/parser/HTMLToken.h:
33
        (WebCore::AtomicHTMLToken::AtomicHTMLToken):
34
1
2013-01-18  Kentaro Hara  <haraken@chromium.org>
35
2013-01-18  Kentaro Hara  <haraken@chromium.org>
2
36
3
        [V8] Remove custom V8ScriptProfileNodeCustom::toV8()
37
        [V8] Remove custom V8ScriptProfileNodeCustom::toV8()
- a/Source/WebCore/WebCore.gypi +2 lines
Lines 3353-3358 a/Source/WebCore/WebCore.gypi_sec1
3353
            'html/parser/HTMLEntityTable.h',
3353
            'html/parser/HTMLEntityTable.h',
3354
            'html/parser/HTMLFormattingElementList.cpp',
3354
            'html/parser/HTMLFormattingElementList.cpp',
3355
            'html/parser/HTMLFormattingElementList.h',
3355
            'html/parser/HTMLFormattingElementList.h',
3356
            'html/parser/HTMLIdentifier.cpp',
3357
            'html/parser/HTMLIdentifier.h',
3356
            'html/parser/HTMLInputStream.h',
3358
            'html/parser/HTMLInputStream.h',
3357
            'html/parser/HTMLMetaCharsetParser.cpp',
3359
            'html/parser/HTMLMetaCharsetParser.cpp',
3358
            'html/parser/HTMLMetaCharsetParser.h',
3360
            'html/parser/HTMLMetaCharsetParser.h',
- a/Source/WebCore/html/parser/BackgroundHTMLParser.cpp -2 / +2 lines
Lines 129-135 void BackgroundHTMLParser::pumpTokenizer() a/Source/WebCore/html/parser/BackgroundHTMLParser.cpp_sec1
129
        const CompactHTMLToken& token = m_pendingTokens.last();
129
        const CompactHTMLToken& token = m_pendingTokens.last();
130
130
131
        if (token.type() == HTMLTokenTypes::StartTag) {
131
        if (token.type() == HTMLTokenTypes::StartTag) {
132
            const String& tagName = token.data();
132
            const String& tagName = token.data().asString();
133
            if (threadSafeMatch(tagName, SVGNames::svgTag)
133
            if (threadSafeMatch(tagName, SVGNames::svgTag)
134
                || threadSafeMatch(tagName, MathMLNames::mathTag))
134
                || threadSafeMatch(tagName, MathMLNames::mathTag))
135
                m_inForeignContent = true;
135
                m_inForeignContent = true;
Lines 150-156 void BackgroundHTMLParser::pumpTokenizer() a/Source/WebCore/html/parser/BackgroundHTMLParser.cpp_sec2
150
                m_tokenizer->setState(HTMLTokenizerState::RAWTEXTState);
150
                m_tokenizer->setState(HTMLTokenizerState::RAWTEXTState);
151
        }
151
        }
152
        if (token.type() == HTMLTokenTypes::EndTag) {
152
        if (token.type() == HTMLTokenTypes::EndTag) {
153
            const String& tagName = token.data();
153
            const String& tagName = token.data().asString();
154
            if (threadSafeMatch(tagName, SVGNames::svgTag) || threadSafeMatch(tagName, MathMLNames::mathTag))
154
            if (threadSafeMatch(tagName, SVGNames::svgTag) || threadSafeMatch(tagName, MathMLNames::mathTag))
155
                m_inForeignContent = false;
155
                m_inForeignContent = false;
156
            if (threadSafeMatch(tagName, scriptTag)) {
156
            if (threadSafeMatch(tagName, scriptTag)) {
- a/Source/WebCore/html/parser/CompactHTMLToken.cpp -8 / +5 lines
Lines 41-47 CompactHTMLToken::CompactHTMLToken(const HTMLToken& token) a/Source/WebCore/html/parser/CompactHTMLToken.cpp_sec1
41
        ASSERT_NOT_REACHED();
41
        ASSERT_NOT_REACHED();
42
        break;
42
        break;
43
    case HTMLTokenTypes::DOCTYPE:
43
    case HTMLTokenTypes::DOCTYPE:
44
        m_data = String(token.name().data(), token.name().size());
44
        m_data = HTMLIdentifier(token.name().data(), token.name().size());
45
        m_publicIdentifier = String(token.publicIdentifier().data(), token.publicIdentifier().size());
45
        m_publicIdentifier = String(token.publicIdentifier().data(), token.publicIdentifier().size());
46
        m_systemIdentifier = String(token.systemIdentifier().data(), token.systemIdentifier().size());
46
        m_systemIdentifier = String(token.systemIdentifier().data(), token.systemIdentifier().size());
47
        break;
47
        break;
Lines 57-67 CompactHTMLToken::CompactHTMLToken(const HTMLToken& token) a/Source/WebCore/html/parser/CompactHTMLToken.cpp_sec2
57
        // Fall through!
57
        // Fall through!
58
    case HTMLTokenTypes::Comment:
58
    case HTMLTokenTypes::Comment:
59
    case HTMLTokenTypes::Character:
59
    case HTMLTokenTypes::Character:
60
        if (token.isAll8BitData())
60
        m_data = HTMLIdentifier(token.name().data(), token.name().size(), token.isAll8BitData());
61
            m_data = String::make8BitFrom16BitSource(token.data().data(), token.data().size());
62
        else
63
            m_data = String(token.data().data(), token.data().size());
64
        break;
65
    default:
61
    default:
66
        ASSERT_NOT_REACHED();
62
        ASSERT_NOT_REACHED();
67
        break;
63
        break;
Lines 89-96 bool CompactHTMLToken::isSafeToSendToAnotherThread() const a/Source/WebCore/html/parser/CompactHTMLToken.cpp_sec3
89
            return false;
85
            return false;
90
    }
86
    }
91
87
92
    return isStringSafeToSendToAnotherThread(m_data)
88
    // FIXME: Check m_data.
93
        && isStringSafeToSendToAnotherThread(m_publicIdentifier)
89
90
    return isStringSafeToSendToAnotherThread(m_publicIdentifier)
94
        && isStringSafeToSendToAnotherThread(m_systemIdentifier);
91
        && isStringSafeToSendToAnotherThread(m_systemIdentifier);
95
}
92
}
96
93
- a/Source/WebCore/html/parser/CompactHTMLToken.h -2 / +3 lines
Lines 28-33 a/Source/WebCore/html/parser/CompactHTMLToken.h_sec1
28
28
29
#if ENABLE(THREADED_HTML_PARSER)
29
#if ENABLE(THREADED_HTML_PARSER)
30
30
31
#include "HTMLIdentifier.h"
31
#include "HTMLTokenTypes.h"
32
#include "HTMLTokenTypes.h"
32
#include <wtf/RefCounted.h>
33
#include <wtf/RefCounted.h>
33
#include <wtf/RefPtr.h>
34
#include <wtf/RefPtr.h>
Lines 61-67 public: a/Source/WebCore/html/parser/CompactHTMLToken.h_sec2
61
    bool isSafeToSendToAnotherThread() const;
62
    bool isSafeToSendToAnotherThread() const;
62
63
63
    HTMLTokenTypes::Type type() const { return m_type; }
64
    HTMLTokenTypes::Type type() const { return m_type; }
64
    const String& data() const { return m_data; }
65
    const HTMLIdentifier& data() const { return m_data; }
65
    bool selfClosing() const { return m_selfClosing; }
66
    bool selfClosing() const { return m_selfClosing; }
66
    const Vector<CompactAttribute>& attributes() const { return m_attributes; }
67
    const Vector<CompactAttribute>& attributes() const { return m_attributes; }
67
68
Lines 70-76 public: a/Source/WebCore/html/parser/CompactHTMLToken.h_sec3
70
71
71
private:
72
private:
72
    HTMLTokenTypes::Type m_type;
73
    HTMLTokenTypes::Type m_type;
73
    String m_data; // "name", "characters", or "data" depending on m_type
74
    HTMLIdentifier m_data; // "name", "characters", or "data" depending on m_type
74
    bool m_selfClosing;
75
    bool m_selfClosing;
75
    Vector<CompactAttribute> m_attributes;
76
    Vector<CompactAttribute> m_attributes;
76
77
- a/Source/WebCore/html/parser/HTMLDocumentParser.cpp +3 lines
Lines 32-37 a/Source/WebCore/html/parser/HTMLDocumentParser.cpp_sec1
32
#include "DocumentFragment.h"
32
#include "DocumentFragment.h"
33
#include "Element.h"
33
#include "Element.h"
34
#include "Frame.h"
34
#include "Frame.h"
35
#include "HTMLIdentifier.h"
35
#include "HTMLNames.h"
36
#include "HTMLNames.h"
36
#include "HTMLParserScheduler.h"
37
#include "HTMLParserScheduler.h"
37
#include "HTMLParserThread.h"
38
#include "HTMLParserThread.h"
Lines 458-463 void HTMLDocumentParser::startBackgroundParser() a/Source/WebCore/html/parser/HTMLDocumentParser.cpp_sec2
458
    ASSERT(!m_haveBackgroundParser);
459
    ASSERT(!m_haveBackgroundParser);
459
    m_haveBackgroundParser = true;
460
    m_haveBackgroundParser = true;
460
461
462
    HTMLIdentifier::init();
463
461
    ParserIdentifier identifier = ParserMap::identifierForParser(this);
464
    ParserIdentifier identifier = ParserMap::identifierForParser(this);
462
    parserMap().mainThreadParsers().set(identifier, this);
465
    parserMap().mainThreadParsers().set(identifier, this);
463
466
- a/Source/WebCore/html/parser/HTMLIdentifier.cpp +102 lines
Line 0 a/Source/WebCore/html/parser/HTMLIdentifier.cpp_sec1
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 "config.h"
27
28
#if ENABLE(THREADED_HTML_PARSER)
29
30
#include "HTMLIdentifier.h"
31
32
#include "HTMLNames.h"
33
#include <wtf/HashMap.h>
34
#include <wtf/MainThread.h>
35
#include <wtf/text/StringHash.h>
36
37
namespace WebCore {
38
39
using namespace HTMLNames;
40
41
static const unsigned invalidIndex = -1;
42
43
typedef std::pair<unsigned, StringImpl*> IdentifierEntry;
44
typedef HashMap<unsigned, Vector<IdentifierEntry>, AlreadyHashed> IdentifierTable;
45
46
static IdentifierTable& identifierTable()
47
{
48
    DEFINE_STATIC_LOCAL(IdentifierTable, table, ());
49
    return table;
50
}
51
52
static unsigned findIndex(const UChar* characters, unsigned length)
53
{
54
    unsigned hash = StringHasher::computeHash(characters, length);
55
    const IdentifierTable& table = identifierTable();
56
57
    IdentifierTable::const_iterator it = table.find(hash);
58
    if (it == table.end())
59
        return invalidIndex;
60
    const Vector<IdentifierEntry>& entries = it->value;
61
    for (size_t i = 0; i < entries.size(); ++i) {
62
        if (equal(entries[i].second, characters, length))
63
            return entries[i].first;
64
    }
65
    return invalidIndex;
66
}
67
68
HTMLIdentifier::HTMLIdentifier(const UChar* characters, unsigned length, bool isAll8BitData)
69
    : m_index(findIndex(characters, length))
70
{
71
    if (m_index != invalidIndex)
72
        return;
73
    m_string = isAll8BitData ? String::make8BitFrom16BitSource(characters, length) : String(characters, length);
74
}
75
76
const String& HTMLIdentifier::asString() const
77
{
78
    if (m_index != invalidIndex)
79
        return getHTMLTags()[m_index]->localName();
80
    return m_string;
81
}
82
83
void HTMLIdentifier::init()
84
{
85
    static bool isInitialized = false;
86
    if (isInitialized)
87
        return;
88
    isInitialized = true;
89
90
    WebCore::QualifiedName** tags = getHTMLTags();
91
    IdentifierTable& table = identifierTable();
92
93
    for (unsigned i = 0; i < HTMLTagsCount; ++i) {
94
        StringImpl* tagName = tags[i]->localName().impl();
95
        unsigned hash = tagName->hash();
96
        table.get(hash).append(IdentifierEntry(i, tagName));
97
    }
98
}
99
100
}
101
102
#endif // ENABLE(THREADED_HTML_PARSER)
- a/Source/WebCore/html/parser/HTMLIdentifier.h +54 lines
Line 0 a/Source/WebCore/html/parser/HTMLIdentifier.h_sec1
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
#ifndef HTMLIdentifier_h
27
#define HTMLIdentifier_h
28
29
#if ENABLE(THREADED_HTML_PARSER)
30
31
#include <wtf/text/AtomicString.h>
32
33
namespace WebCore {
34
35
class HTMLIdentifier {
36
public:
37
    HTMLIdentifier() : m_index(0) { }
38
    HTMLIdentifier(const UChar* characters, unsigned length, bool isAll8BitData = false);
39
40
    bool equals(unsigned index);
41
    const String& asString() const;
42
43
    static void init();
44
45
private:
46
    unsigned m_index;
47
    String m_string;
48
};
49
50
}
51
52
#endif // ENABLE(THREADED_HTML_PARSER)
53
54
#endif
- a/Source/WebCore/html/parser/HTMLToken.h -6 / +8 lines
Lines 104-110 private: a/Source/WebCore/html/parser/HTMLToken.h_sec1
104
            ASSERT_NOT_REACHED();
104
            ASSERT_NOT_REACHED();
105
            break;
105
            break;
106
        case HTMLTokenTypes::DOCTYPE:
106
        case HTMLTokenTypes::DOCTYPE:
107
            m_name = token.data();
107
            m_name = token.data().asString();
108
            m_doctypeData = adoptPtr(new HTMLToken::DoctypeData());
108
            m_doctypeData = adoptPtr(new HTMLToken::DoctypeData());
109
            m_doctypeData->m_hasPublicIdentifier = true;
109
            m_doctypeData->m_hasPublicIdentifier = true;
110
            m_doctypeData->m_publicIdentifier.append(token.publicIdentifier().characters(), token.publicIdentifier().length());
110
            m_doctypeData->m_publicIdentifier.append(token.publicIdentifier().characters(), token.publicIdentifier().length());
Lines 120-134 private: a/Source/WebCore/html/parser/HTMLToken.h_sec2
120
            // Fall through!
120
            // Fall through!
121
        case HTMLTokenTypes::EndTag:
121
        case HTMLTokenTypes::EndTag:
122
            m_selfClosing = token.selfClosing();
122
            m_selfClosing = token.selfClosing();
123
            m_name = AtomicString(token.data());
123
            m_name = AtomicString(token.data().asString());
124
            break;
124
            break;
125
        case HTMLTokenTypes::Comment:
125
        case HTMLTokenTypes::Comment:
126
            m_data = token.data();
126
            m_data = token.data().asString();
127
            break;
127
            break;
128
        case HTMLTokenTypes::Character:
128
        case HTMLTokenTypes::Character: {
129
            m_externalCharacters = token.data().characters();
129
            const String& text = token.data().asString();
130
            m_externalCharactersLength = token.data().length();
130
            m_externalCharacters = text.characters();
131
            m_externalCharactersLength = text.length();
131
            break;
132
            break;
133
        }
132
        default:
134
        default:
133
            break;
135
            break;
134
        }
136
        }

Return to Bug 107337