private static boolean shouldReplaceWithAlias ( String str , StringInfo info ) { // Optimize for code size. Are aliases smaller than strings? // // This logic optimizes for the size of uncompressed code, but it tends to // get good results for the size of the gzipped code too. // // gzip actually prefers that strings are not aliased - it compresses N // string literals better than 1 string literal and N+1 short variable // names, provided each string is within 32k of the previous copy. We // follow the uncompressed logic as insurance against there being multiple // strings more than 32k apart. int sizeOfLiteral = 2 + str . length ( ) ; int sizeOfStrings = info . numOccurrences * sizeOfLiteral ; int sizeOfVariable = 3 ; // '6' comes from: 'var =;' in var XXX="..."; int sizeOfAliases = 6 + sizeOfVariable + sizeOfLiteral // declaration + info . numOccurrences * sizeOfVariable ; // + uses return sizeOfAliases < sizeOfStrings ; }
Dictates the policy for replacing a string with an alias .