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

Side by Side Diff: third_party/WebKit/Source/build/scripts/templates/ElementLookupTrie.cpp.tmpl

Issue 1978703002: Factor and simplify generation of the lookup trie used for HTMLLookupTrie. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove newlines Created 4 years, 7 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 {% from 'macros.tmpl' import license %} 1 {% from 'macros.tmpl' import trie_length_switch %}
2 {{license()}} 2 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
3 {% macro trie_switch(trie, index) %} 3 // Use of this source code is governed by a BSD-style license that can be
4 {# FIXME: No need to switch if there's only a single item in the subtrie: 4 // found in the LICENSE file.
5 can just have an if statement as we're currently doing for leaves. #}
6 switch (data[{{index}}]) {
7 {% for char, subtrie, tag, conditions in trie %}
8 case '{{char}}':
9 {% if subtrie %}{# Recurse on subtrie #}
10 {{trie_switch(subtrie, index + 1) | indent}}
11 {% elif conditions %}{# Check suffix #}
12 if ({{conditions | join(' && ')}})
13 return {{tag}}Tag.localName().impl();
14 return 0;
15 {% else %}{# Terminal node (no suffix) #}
16 return {{tag}}Tag.localName().impl();
17 {% endif %}
18 {% endfor %}
19 }
20 return 0;
21 {% endmacro %}
22 5
23 #include "{{namespace}}ElementLookupTrie.h" 6 #include "{{namespace}}ElementLookupTrie.h"
24 7
25 #include "{{namespace}}Names.h" 8 #include "{{namespace}}Names.h"
26 9
27 namespace blink { 10 namespace blink {
28 11
29 using namespace {{namespace}}Names; 12 using namespace {{namespace}}Names;
30 13
31 StringImpl* lookup{{namespace}}Tag(const UChar* data, unsigned length) 14 StringImpl* lookup{{namespace}}Tag(const UChar* data, unsigned length)
32 { 15 {
33 ASSERT(data); 16 DCHECK(data);
34 ASSERT(length); 17 DCHECK(length);
35 switch (length) { 18 {% macro trie_return_statement(tag) %}{{tag}}Tag.localName().impl(){% endmac ro %}
36 {% for length, trie in length_tries %} 19 {{ trie_length_switch(length_tries, trie_return_statement, false) | indent(4 ) }}
37 case {{length}}: 20 return nullptr;
38 {{trie_switch(trie, 0) | indent(8)}}
39 {% endfor %}
40 }
41 return 0;
42 } 21 }
43 22
44 } // namespace blink 23 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/build/scripts/scripts.gypi ('k') | third_party/WebKit/Source/build/scripts/templates/macros.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698