Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLSourceTracker.cpp

Issue 2717303002: Considering HTMLTokenizer state in HTMLSourceTracker (Closed)
Patch Set: Considering HTMLTokenizer state in HTMLSourceTracker Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Adam Barth. All Rights Reserved. 2 * Copyright (C) 2010 Adam Barth. 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 19 matching lines...) Expand all
30 30
31 namespace blink { 31 namespace blink {
32 32
33 HTMLSourceTracker::HTMLSourceTracker() : m_isStarted(false) {} 33 HTMLSourceTracker::HTMLSourceTracker() : m_isStarted(false) {}
34 34
35 void HTMLSourceTracker::start(SegmentedString& currentInput, 35 void HTMLSourceTracker::start(SegmentedString& currentInput,
36 HTMLTokenizer* tokenizer, 36 HTMLTokenizer* tokenizer,
37 HTMLToken& token) { 37 HTMLToken& token) {
38 if (token.type() == HTMLToken::Uninitialized && !m_isStarted) { 38 if (token.type() == HTMLToken::Uninitialized && !m_isStarted) {
39 m_previousSource.clear(); 39 m_previousSource.clear();
40 if (tokenizer->numberOfBufferedCharacters()) 40 if (needToCheckTokenizerBuffer(tokenizer) &&
41 tokenizer->numberOfBufferedCharacters())
41 m_previousSource = tokenizer->bufferedCharacters(); 42 m_previousSource = tokenizer->bufferedCharacters();
42 } else 43 } else
43 m_previousSource.append(m_currentSource); 44 m_previousSource.append(m_currentSource);
Charlie Harrison 2017/03/07 18:37:48 while you are here could you add braces to the els
wanchang 2017/03/08 00:35:35 Done.
44 45
45 m_isStarted = true; 46 m_isStarted = true;
46 m_currentSource = currentInput; 47 m_currentSource = currentInput;
47 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() - 48 token.setBaseOffset(m_currentSource.numberOfCharactersConsumed() -
48 m_previousSource.length()); 49 m_previousSource.length());
49 } 50 }
50 51
51 void HTMLSourceTracker::end(SegmentedString& currentInput, 52 void HTMLSourceTracker::end(SegmentedString& currentInput,
52 HTMLTokenizer* tokenizer, 53 HTMLTokenizer* tokenizer,
53 HTMLToken& token) { 54 HTMLToken& token) {
54 m_isStarted = false; 55 m_isStarted = false;
55 56
56 m_cachedSourceForToken = String(); 57 m_cachedSourceForToken = String();
57 58
58 // FIXME: This work should really be done by the HTMLTokenizer. 59 // FIXME: This work should really be done by the HTMLTokenizer.
60 size_t numberOfBufferedCharacters = 0u;
61 if (needToCheckTokenizerBuffer(tokenizer)) {
62 numberOfBufferedCharacters = tokenizer->numberOfBufferedCharacters();
63 }
59 token.end(currentInput.numberOfCharactersConsumed() - 64 token.end(currentInput.numberOfCharactersConsumed() -
60 tokenizer->numberOfBufferedCharacters()); 65 numberOfBufferedCharacters);
61 } 66 }
62 67
63 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) { 68 String HTMLSourceTracker::sourceForToken(const HTMLToken& token) {
64 if (!m_cachedSourceForToken.isEmpty()) 69 if (!m_cachedSourceForToken.isEmpty())
65 return m_cachedSourceForToken; 70 return m_cachedSourceForToken;
66 71
67 size_t length; 72 size_t length;
68 if (token.type() == HTMLToken::EndOfFile) { 73 if (token.type() == HTMLToken::EndOfFile) {
69 // Consume the remainder of the input, omitting the null character we use to 74 // Consume the remainder of the input, omitting the null character we use to
70 // mark the end of the file. 75 // mark the end of the file.
(...skipping 14 matching lines...) Expand all
85 for (; i < length; ++i) { 90 for (; i < length; ++i) {
86 ASSERT(!m_currentSource.isEmpty()); 91 ASSERT(!m_currentSource.isEmpty());
87 source.append(m_currentSource.currentChar()); 92 source.append(m_currentSource.currentChar());
88 m_currentSource.advance(); 93 m_currentSource.advance();
89 } 94 }
90 95
91 m_cachedSourceForToken = source.toString(); 96 m_cachedSourceForToken = source.toString();
92 return m_cachedSourceForToken; 97 return m_cachedSourceForToken;
93 } 98 }
94 99
100 bool HTMLSourceTracker::needToCheckTokenizerBuffer(HTMLTokenizer* tokenizer) {
101 HTMLTokenizer::State state = tokenizer->getState();
102 // considering tokenizer temporarybuffer only if in the middle of
Charlie Harrison 2017/03/07 18:37:47 Phrasing suggestion: "Consider checking the tokeni
wanchang 2017/03/08 00:35:35 Done.
103 // endtagbufferingstate or completed parsing the token
104 return state == HTMLTokenizer::DataState || isEndTagBufferingState(state);
105 }
106
95 } // namespace blink 107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698