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

Unified Diff: third_party/WebKit/Source/build/scripts/templates/macros.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 some unused imports 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 side-by-side diff with in-line comments
Download patch
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..35ff53ce09ea13c35abd1e7e31f872bc2a81125d 100644
--- a/third_party/WebKit/Source/build/scripts/templates/macros.tmpl
+++ b/third_party/WebKit/Source/build/scripts/templates/macros.tmpl
@@ -6,3 +6,53 @@
// 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, object, return_macro, lowercase_data) %}
+{% for name, value in object.items() %}
+ {% if name|length %}
+if (
+ {%- for c in name -%}
+ {%- if lowercase_data -%}
+ {{ " && " if not loop.first }}toASCIILower(data[{{index + loop.index0}}]) == '{{c}}'
+ {%- else -%}
+ {{ " && " if not loop.first }}data[{{index + loop.index0}}] == '{{c}}'
+ {%- endif -%}
+ {%- endfor -%}
+ )
+ return {{ return_macro(value) }};
+break;
+ {% else %}
+return {{ return_macro(value) }};
+ {% endif %}
+{% endfor %}
+{% endmacro %}
+
+
+{% macro trie_switch(trie, index, return_macro, lowercase_data) %}
Timothy Loh 2016/05/13 04:49:17 Do you think it would be clearer to merge the macr
meade_UTC10 2016/05/13 06:48:20 Hmm, I think it's clearer to have the trie_leaf ma
+{% if lowercase_data %}
+switch (toASCIILower(data[{{index}}])) {
+{% else %}
+switch (data[{{index}}]) {
+{% endif %}
+{% for char, value in trie.items()|sort %}
+case '{{char}}':
+ {% if value|length == 1 and value.items()[0][1] is string %}
+ {{ trie_leaf(index+1, value, return_macro, lowercase_data) | indent(4) }}
+ {% else %}
+ {{ trie_switch(value, index + 1, return_macro, lowercase_data) | indent(4) }}
+ {% endif %}
+{% endfor %}
+}
+break;
+{% endmacro %}
+
+
+{% macro trie_length_switch(length_tries, return_macro, default_return_value, lowercase_data) %}
Timothy Loh 2016/05/13 05:41:33 default_return_value isn't used any more
meade_UTC10 2016/05/13 06:48:20 Done.
+switch(length) {
Timothy Loh 2016/05/13 04:49:17 Space after switch
meade_UTC10 2016/05/13 06:48:20 Done.
+{% for length, trie in length_tries %}
+case {{ length }}:
+ {{ trie_switch(trie, 0, return_macro, lowercase_data) | indent(4) }}
+{% endfor %}
+}
+{% endmacro %}

Powered by Google App Engine
This is Rietveld 408576698