OLD | NEW |
---|---|
1 {% from 'macros.tmpl' import license %} | 1 {% from 'macros.tmpl' import license %} |
2 {% from 'macros.tmpl' import trie_length_switch %} | |
3 {% macro trie_return_statement(tag) %}{{tag}}Tag.localName().impl(){% endmacro % } | |
Timothy Loh
2016/05/12 07:03:14
can this line go immediately before the trie_lengt
meade_UTC10
2016/05/13 03:48:19
Done.
| |
2 {{license()}} | 4 {{license()}} |
3 {% macro trie_switch(trie, index) %} | |
4 {# FIXME: No need to switch if there's only a single item in the subtrie: | |
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 {{ trie_length_switch(none, length_tries, trie_return_statement, '0') | inde nt(4) }} |
Timothy Loh
2016/05/12 07:03:14
0 -> nullptr
meade_UTC10
2016/05/13 03:48:19
Done.
| |
36 {% for length, trie in length_tries %} | |
37 case {{length}}: | |
38 {{trie_switch(trie, 0) | indent(8)}} | |
39 {% endfor %} | |
40 } | |
41 return 0; | |
42 } | 19 } |
43 | 20 |
44 } // namespace blink | 21 } // namespace blink |
OLD | NEW |