Skip to content
Commit 8e1c1f4d authored by Tobias Thierer's avatar Tobias Thierer
Browse files

Minimize default MIME map and optimize loading.

This CL topic speeds up DefaultMimeMapFactory.create() from 15.5msec
to 5.7msec (measured by bundling a copy of the logic and data into
a test app) and saves 5.2 KByte of space (16 KBytes uncompressed) in
framework.jar. This CL topic does not change the amount of heap memory
consumed by the loaded MimeMap.

This is achieved by moving the following parsing steps from
DefaultMimeMapFactory into a build-time optimization step:

 * strip off comments (starting with '#')
 * normalize whitespace (trim leading and trailing whitespace;
   replace remaining whitespace with a single ' ').
 * drop lines that do not contain a ' ' after this step (those
   only contained comments or only a MIME type without any
   extension).
 * use String.indexOf(char) in favor of String.contains(String) or
   Pattern matching.

Noteworthy extra step specific to this CL:
 * specifically for vendor.mime.types (but not android.mime.types),
   add a prefix '?' to MIME types and extensions at build time,
   rather than at runtime.

Note that after this CL, DefaultMimeMapFactory can now *only* parse
minimized *mime.types files, not the original (non-minimized) file
format.

Test: Checked that the mapping didn't change by checking that
      a device flashed after this CL passes CtsMimeMapTestCases
      built before this CL.
Test: Ran "make mimemap-res.jar" and manually verified that files
      in the resulting jar look as expected.
Test: Locally added some extra mappings to vendor.mime.types, some
      of them with a leading '?', and verified that they all show
      up with exactly one leading '?' for the MIME type and each
      extension within mimemap-res.jar.
Bug: 142267887

Change-Id: Idf1ef945a4ac225476f2036fbc8bb35eb9c090af
parent 04665dbf
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment