Index: third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
diff --git a/third_party/WebKit/Source/build/scripts/templates/macros.tmpl b/third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
index 064dd985221d257994df2387b101d11eb14a634d..383b0611282dd4980b791f65486f192cfa6a4070 100644 |
--- a/third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
+++ b/third_party/WebKit/Source/build/scripts/templates/macros.tmpl |
@@ -6,3 +6,48 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
{%- endmacro %} |
+ |
+{% macro trie_leaf(index, entry, return_macro, default_return_value) %} |
Timothy Loh
2016/05/03 07:40:25
We'll need a flag should_lower since unlike the ta
|
+{% if entry.conditions %} |
+if ({{entry.conditions | join(' && ')}}) |
+ {{return_macro(entry.value)}} |
+{% else %} |
+if (data[{{index}}] == '{{entry.char}}') |
+ {{return_macro(entry.value)}} |
+{% endif %} |
+return {{default_return_value}}; |
Timothy Loh
2016/05/03 07:40:25
It might be possible to make this a "break" so we
meade_UTC10
2016/05/04 07:24:54
Done.
|
+{% endmacro %} |
+ |
+{% macro trie_switch(trie, index, return_macro, default_return_value) %} |
+switch (data[{{index}}]) { |
+{% for entry in trie %} |
+case '{{entry.char}}': |
+ {% if entry.subtrie %} |
+ {{trie_switch(entry.subtrie, index + 1, return_macro, default_return_value) | indent}} |
+ {% elif entry.conditions %}{# Check suffix #} |
+ {{trie_leaf(index, entry, return_macro, default_return_value)}} |
+ {% else %}{# Terminal node (no suffix) #} |
+ {{return_macro(entry.value)}} |
+ {% endif %} |
+{% endfor %} |
+} |
+return {{default_return_value}}; |
+{% endmacro %} |
+ |
+{% macro trie_length_switch(empty_case_return_value, length_tries, return_macro, default_return_value) %} |
+switch (length) { |
+{% if empty_case_return_value %} |
+ case 0: |
+ {{return_macro(empty_case_return_value)}} |
+{% endif %} |
+{% for length, trie in length_tries %} |
+ case {{length}}: |
+ {% if trie|length > 1 or trie[0].subtrie %} |
+ {{trie_switch(trie, 0, return_macro, default_return_value) | indent(8)}} |
+ {% else %} |
+ {{trie_leaf(0, trie[0], return_macro, default_return_value) | indent(8)}} |
+ {% endif %} |
+{% endfor %} |
+ } |
+ return {{default_return_value}}; |
+{% endmacro %} |