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

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 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 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..17a9f4952f510ce1664c028439103e7c6cf4fc56 100644
--- a/third_party/WebKit/Source/build/scripts/templates/macros.tmpl
+++ b/third_party/WebKit/Source/build/scripts/templates/macros.tmpl
@@ -6,3 +6,52 @@
// 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) %}
+{% set name, value = object.items()[0] %}
+{% 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 %}
+{% endmacro %}
+
+
+{% macro trie_switch(trie, index, return_macro, lowercase_data) %}
+{% if trie|length == 1 and trie.values()[0] is string %}
+{{ trie_leaf(index, trie, return_macro, lowercase_data) -}}
+{% else %}
+ {% if lowercase_data %}
+switch (toASCIILower(data[{{index}}])) {
+ {% else %}
+switch (data[{{index}}]) {
+ {% endif %}
+ {% for char, value in trie.items()|sort %}
+case '{{char}}':
+ {{ trie_switch(value, index + 1, return_macro, lowercase_data) | indent(4) }}
+ {% endfor %}
+}
+break;
+{% endif %}
+{% endmacro %}
+
+
+{% macro trie_length_switch(length_tries, return_macro, lowercase_data) %}
+switch (length) {
+{% 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