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

Side by Side Diff: build/android/gyp/process_resources.py

Issue 2573613002: Shrink onResourcesLoaded() code size in webview/monochrome R.java (Closed)
Patch Set: Addressing comments Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Process Android resources to generate R.java, and prepare for packaging. 7 """Process Android resources to generate R.java, and prepare for packaging.
8 8
9 This will crunch images and generate v14 compatible resources 9 This will crunch images and generate v14 compatible resources
10 (see generate_v14_compatible_resources.py). 10 (see generate_v14_compatible_resources.py).
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 raise Exception('Unexpected line in R.txt: %s' % line) 192 raise Exception('Unexpected line in R.txt: %s' % line)
193 java_type, resource_type, name, value = m.groups() 193 java_type, resource_type, name, value = m.groups()
194 ret.append(TextSymbolsEntry(java_type, resource_type, name, value)) 194 ret.append(TextSymbolsEntry(java_type, resource_type, name, value))
195 return ret 195 return ret
196 196
197 197
198 def _CreateRJavaFile(package, resources_by_type, shared_resources): 198 def _CreateRJavaFile(package, resources_by_type, shared_resources):
199 """Generates the contents of a R.java file.""" 199 """Generates the contents of a R.java file."""
200 # Keep these assignments all on one line to make diffing against regular 200 # Keep these assignments all on one line to make diffing against regular
201 # aapt-generated files easier. 201 # aapt-generated files easier.
202 create_id = ('{{ e.resource_type }}.{{ e.name }} = ' 202 create_id = ('{{ e.resource_type }}.{{ e.name }} ^= packageIdTransform;')
203 '({{ e.resource_type }}.{{ e.name }} & 0x00ffffff) |' 203 create_id_arr = ('{{ e.resource_type }}.{{ e.name }}[i] ^='
204 ' (packageId << 24);') 204 ' packageIdTransform;')
205 create_id_arr = ('{{ e.resource_type }}.{{ e.name }}[i] = '
206 '({{ e.resource_type }}.{{ e.name }}[i] & 0x00ffffff) |'
207 ' (packageId << 24);')
208 # Here we diverge from what aapt does. Because we have so many 205 # Here we diverge from what aapt does. Because we have so many
209 # resources, the onResourcesLoaded method was exceeding the 64KB limit that 206 # resources, the onResourcesLoaded method was exceeding the 64KB limit that
210 # Java imposes. For this reason we split onResourcesLoaded into different 207 # Java imposes. For this reason we split onResourcesLoaded into different
211 # methods for each resource type. 208 # methods for each resource type.
212 template = Template("""/* AUTO-GENERATED FILE. DO NOT MODIFY. */ 209 template = Template("""/* AUTO-GENERATED FILE. DO NOT MODIFY. */
213 210
214 package {{ package }}; 211 package {{ package }};
215 212
216 public final class R { 213 public final class R {
214 private static boolean sResourcesDidLoad;
217 {% for resource_type in resource_types %} 215 {% for resource_type in resource_types %}
218 public static final class {{ resource_type }} { 216 public static final class {{ resource_type }} {
219 {% for e in resources[resource_type] %} 217 {% for e in resources[resource_type] %}
220 {% if shared_resources %} 218 {% if shared_resources %}
221 public static {{ e.java_type }} {{ e.name }} = {{ e.value }}; 219 public static {{ e.java_type }} {{ e.name }} = {{ e.value }};
222 {% else %} 220 {% else %}
223 public static final {{ e.java_type }} {{ e.name }} = {{ e.value }}; 221 public static final {{ e.java_type }} {{ e.name }} = {{ e.value }};
224 {% endif %} 222 {% endif %}
225 {% endfor %} 223 {% endfor %}
226 } 224 }
227 {% endfor %} 225 {% endfor %}
228 {% if shared_resources %} 226 {% if shared_resources %}
229 public static void onResourcesLoaded(int packageId) { 227 public static void onResourcesLoaded(int packageId) {
228 assert !sResourcesDidLoad;
229 sResourcesDidLoad = true;
230 int packageIdTransform = (packageId ^ 0x7f) << 24;
230 {% for resource_type in resource_types %} 231 {% for resource_type in resource_types %}
231 onResourcesLoaded{{ resource_type|title }}(packageId); 232 onResourcesLoaded{{ resource_type|title }}(packageIdTransform);
232 {% for e in resources[resource_type] %} 233 {% for e in resources[resource_type] %}
233 {% if e.java_type == 'int[]' %} 234 {% if e.java_type == 'int[]' %}
234 for(int i = 0; i < {{ e.resource_type }}.{{ e.name }}.length; ++i) { 235 for(int i = 0; i < {{ e.resource_type }}.{{ e.name }}.length; ++i) {
235 """ + create_id_arr + """ 236 """ + create_id_arr + """
236 } 237 }
237 {% endif %} 238 {% endif %}
238 {% endfor %} 239 {% endfor %}
239 {% endfor %} 240 {% endfor %}
240 } 241 }
241 {% for res_type in resource_types %} 242 {% for res_type in resource_types %}
242 private static void onResourcesLoaded{{ res_type|title }}(int packageId) { 243 private static void onResourcesLoaded{{ res_type|title }} (
244 int packageIdTransform) {
243 {% for e in resources[res_type] %} 245 {% for e in resources[res_type] %}
244 {% if res_type != 'styleable' and e.java_type != 'int[]' %} 246 {% if res_type != 'styleable' and e.java_type != 'int[]' %}
245 """ + create_id + """ 247 """ + create_id + """
246 {% endif %} 248 {% endif %}
247 {% endfor %} 249 {% endfor %}
248 } 250 }
249 {% endfor %} 251 {% endfor %}
250 {% endif %} 252 {% endif %}
251 } 253 }
252 """, trim_blocks=True, lstrip_blocks=True) 254 """, trim_blocks=True, lstrip_blocks=True)
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 options, 534 options,
533 input_paths=input_paths, 535 input_paths=input_paths,
534 input_strings=input_strings, 536 input_strings=input_strings,
535 output_paths=output_paths, 537 output_paths=output_paths,
536 # TODO(agrieve): Remove R_dir when it's no longer used (used only by GYP). 538 # TODO(agrieve): Remove R_dir when it's no longer used (used only by GYP).
537 force=options.R_dir) 539 force=options.R_dir)
538 540
539 541
540 if __name__ == '__main__': 542 if __name__ == '__main__':
541 main(sys.argv[1:]) 543 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698