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

Side by Side Diff: grit/format/data_pack.py

Issue 244893005: Speed-up whitelist check in data_pack.py (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 6 years, 8 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 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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Support for formatting a data pack file used for platform agnostic resource 6 """Support for formatting a data pack file used for platform agnostic resource
7 files. 7 files.
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 all resources. 120 all resources.
121 121
122 Raises: 122 Raises:
123 KeyError: if there are duplicate keys or resource encoding is 123 KeyError: if there are duplicate keys or resource encoding is
124 inconsistent. 124 inconsistent.
125 """ 125 """
126 input_data_packs = [ReadDataPack(filename) for filename in input_files] 126 input_data_packs = [ReadDataPack(filename) for filename in input_files]
127 whitelist = None 127 whitelist = None
128 if whitelist_file: 128 if whitelist_file:
129 whitelist = util.ReadFile(whitelist_file, util.RAW_TEXT).strip().split('\n') 129 whitelist = util.ReadFile(whitelist_file, util.RAW_TEXT).strip().split('\n')
130 whitelist = map(int, whitelist) 130 whitelist = set(map(int, whitelist))
131 resources, encoding = RePackFromDataPackStrings(input_data_packs, whitelist) 131 resources, encoding = RePackFromDataPackStrings(input_data_packs, whitelist)
132 WriteDataPack(resources, output_file, encoding) 132 WriteDataPack(resources, output_file, encoding)
133 133
134 134
135 def RePackFromDataPackStrings(inputs, whitelist): 135 def RePackFromDataPackStrings(inputs, whitelist):
136 """Returns a data pack string that combines the resources from inputs. 136 """Returns a data pack string that combines the resources from inputs.
137 137
138 Args: 138 Args:
139 inputs: a list of data pack strings that need to be combined. 139 inputs: a list of data pack strings that need to be combined.
140 whitelist: a list of resource IDs that should be kep in the output string 140 whitelist: a list of resource IDs that should be kep in the output string
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 # Just write a simple file. 199 # Just write a simple file.
200 data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''} 200 data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''}
201 WriteDataPack(data, 'datapack1.pak', UTF8) 201 WriteDataPack(data, 'datapack1.pak', UTF8)
202 data2 = {1000: 'test', 5: 'five'} 202 data2 = {1000: 'test', 5: 'five'}
203 WriteDataPack(data2, 'datapack2.pak', UTF8) 203 WriteDataPack(data2, 'datapack2.pak', UTF8)
204 print 'wrote datapack1 and datapack2 to current directory.' 204 print 'wrote datapack1 and datapack2 to current directory.'
205 205
206 206
207 if __name__ == '__main__': 207 if __name__ == '__main__':
208 main() 208 main()
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