diff options
author | Mohamed Heikal <mheikal@google.com> | 2019-07-22 17:12:01 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-07-22 17:12:01 +0000 |
commit | 60ca0dbefb5240d3dab2461b086b57bb96be3e40 (patch) | |
tree | 3198198f166fbe774eae7b14615e694edd606d53 /tools/aapt2/optimize/ResourcePathShortener.cpp | |
parent | 1b23258c87f13c17eafb8dccb0871dc138dc6b25 (diff) | |
parent | 525714a88bef5743016431c171cdc61bad45427e (diff) |
Merge "Precalculate the required number of characters for path shortening"
Diffstat (limited to 'tools/aapt2/optimize/ResourcePathShortener.cpp')
-rw-r--r-- | tools/aapt2/optimize/ResourcePathShortener.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/tools/aapt2/optimize/ResourcePathShortener.cpp b/tools/aapt2/optimize/ResourcePathShortener.cpp index 6b11de759d2d..7f5d10475f93 100644 --- a/tools/aapt2/optimize/ResourcePathShortener.cpp +++ b/tools/aapt2/optimize/ResourcePathShortener.cpp @@ -16,7 +16,6 @@ #include "optimize/ResourcePathShortener.h" -#include <math.h> #include <unordered_set> #include "androidfw/StringPiece.h" @@ -51,18 +50,15 @@ std::string ShortenFileName(const android::StringPiece& file_path, int output_le } -// Calculate the optimal hash length such that an average of 10% of resources -// collide in their shortened path. +// Return the optimal hash length such that at most 10% of resources collide in +// their shortened path. // Reference: http://matt.might.net/articles/counting-hash-collisions/ int OptimalShortenedLength(int num_resources) { - int num_chars = 2; - double N = 64*64; // hash space when hash is 2 chars long - double max_collisions = num_resources * 0.1; - while (num_resources - N + N * pow((N - 1) / N, num_resources) > max_collisions) { - N *= 64; - num_chars++; + if (num_resources > 4000) { + return 3; + } else { + return 2; } - return num_chars; } std::string GetShortenedPath(const android::StringPiece& shortened_filename, |