diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-11 17:45:38 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-11 17:45:38 +0000 |
commit | 5078bb0c94c72c8cbcbf05cfd4da99e45f51f61e (patch) | |
tree | 24ccf8cb8658f801bdc1f9be812a92ed668b59c0 /tools/data_pack | |
parent | 81ac4a3fd428d19ec78072b8614a354cf0cc5c18 (diff) | |
download | chromium_src-5078bb0c94c72c8cbcbf05cfd4da99e45f51f61e.zip chromium_src-5078bb0c94c72c8cbcbf05cfd4da99e45f51f61e.tar.gz chromium_src-5078bb0c94c72c8cbcbf05cfd4da99e45f51f61e.tar.bz2 |
Remove the length field from the index entries in data pack files.
After the last index entry, we put an extra entry (id of 0, offset
pointing to where the next entry would start) so we can compute
the size of the last index entry.
This saves 4 bytes per item in data pack files, which is about 10k per
locale pak file. When compressed, this saves about 237k.
BUG=76285
Review URL: http://codereview.chromium.org/7604012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/data_pack')
-rwxr-xr-x | tools/data_pack/data_pack.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/tools/data_pack/data_pack.py b/tools/data_pack/data_pack.py index 571842e..ffd2cb2 100755 --- a/tools/data_pack/data_pack.py +++ b/tools/data_pack/data_pack.py @@ -9,7 +9,7 @@ See base/pack_file* for details. import struct -FILE_FORMAT_VERSION = 2 +FILE_FORMAT_VERSION = 3 HEADER_LENGTH = 2 * 4 # Two uint32s. (file version and number of entries) class WrongFileVersion(Exception): @@ -26,13 +26,17 @@ def ReadDataPack(input_file): raise WrongFileVersion resources = {} + if num_entries == 0: + return resources + # Read the index and data. data = data[HEADER_LENGTH:] - kIndexEntrySize = 2 + 2 * 4 # Each entry is 1 uint16 and 2 uint32s. + kIndexEntrySize = 2 + 4 # Each entry is a uint16 and a uint32. for _ in range(num_entries): - id, offset, length = struct.unpack("<HII", data[:kIndexEntrySize]) + id, offset = struct.unpack("<HI", data[:kIndexEntrySize]) data = data[kIndexEntrySize:] - resources[id] = original_data[offset:offset + length] + next_id, next_offset = struct.unpack("<HI", data[:kIndexEntrySize]) + resources[id] = original_data[offset:next_offset] return resources @@ -44,15 +48,18 @@ def WriteDataPack(resources, output_file): # Write file header. file.write(struct.pack("<II", FILE_FORMAT_VERSION, len(ids))) - # Each entry is 1 uint16 and 2 uint32s. - index_length = len(ids) * (2 + 2 * 4) + # Each entry is a uint16 and a uint32. We have one extra entry for the last + # item. + index_length = (len(ids) + 1) * (2 + 4) # Write index. data_offset = HEADER_LENGTH + index_length for id in ids: - file.write(struct.pack("<HII", id, data_offset, len(resources[id]))) + file.write(struct.pack("<HI", id, data_offset)) data_offset += len(resources[id]) + file.write(struct.pack("<HI", 0, data_offset)) + # Write data. for id in ids: file.write(resources[id]) |