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

Unified Diff: lib/compiler/implementation/js_backend/minify_namer.dart

Issue 11307009: Revert "Minifying renamer for classes, methods and instance variables." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/js_backend/minify_namer.dart
diff --git a/lib/compiler/implementation/js_backend/minify_namer.dart b/lib/compiler/implementation/js_backend/minify_namer.dart
deleted file mode 100644
index 4ca05544591e08517ee263596e88d3108229b3da..0000000000000000000000000000000000000000
--- a/lib/compiler/implementation/js_backend/minify_namer.dart
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-/**
- * Assigns JavaScript identifiers to Dart variables, class-names and members.
- */
-class MinifyNamer extends Namer {
- MinifyNamer(Compiler compiler) : super(compiler);
-
- String get ISOLATE => 'I';
- String get ISOLATE_PROPERTIES => 'p';
- bool get shouldMinify => true;
-
- const ALPHABET_CHARACTERS = 52; // a-zA-Z.
- const ALPHANUMERIC_CHARACTERS = 62; // a-zA-Z0-9.
-
- String getFreshName(String proposedName, Set<String> usedNames) {
- var freshName = _getUnusedName(proposedName, usedNames);
- usedNames.add(freshName);
- return freshName;
- }
-
- // This gets a minified name based on a hash of the proposed name. This
- // is slightly less efficient than just getting the next name in a series,
- // but it means that small changes in the input program will give smallish
- // changes in the output, which can be useful for diffing etc.
- String _getUnusedName(String proposedName, Set<String> usedNames) {
- // Try single-character names with characters that occur in the
- // input.
- for (int i = 0; i < proposedName.length; i++) {
- String candidate = proposedName[i];
- int code = candidate.charCodeAt(0);
- if (code < $A) continue;
- if (code > $z) continue;
- if (code > $Z && code < $a) continue;
- if (!usedNames.contains(candidate)) return candidate;
- }
-
- int hash = _calculateHash(proposedName);
- // Avoid very small hashes that won't try many names.
- hash = hash < 1000 ? hash * 314159 : hash; // Yes, it's prime.
-
- // Try other n-character names based on the hash. We try one to three
- // character identifiers. For each length we try around 10 different names
- // in a predictable order determined by the proposed name. This is in order
- // to make the renamer stable: small changes in the input should nornally
- // result in relatively small changes in the output.
- for (var n = 1; n <= 3; n++) {
- int h = hash;
- while (h > 10) {
- var codes = <int>[_letterNumber(h)];
- int h2 = h ~/ ALPHABET_CHARACTERS;
- for (var i = 1; i < n; i++) {
- codes.add(_alphaNumericNumber(h2));
- h2 ~/= ALPHANUMERIC_CHARACTERS;
- }
- final candidate = new String.fromCharCodes(codes);
- if (!usedNames.contains(candidate) && !jsReserved.contains(candidate)) {
- return candidate;
- }
- // Try again with a slightly different hash. After around 10 turns
- // around this loop h is zero and we try a longer name.
- h ~/= 7;
- }
- }
-
- // If we can't find a hash based name in the three-letter space, then base
- // the name on a letter and a counter.
- proposedName = new String.fromCharCodes([_letterNumber(hash)]);
- var i = 0;
- while (usedNames.contains("$proposedName$i")) {
- i++;
- }
- return "$proposedName$i";
- }
-
- int _calculateHash(String name) {
- int h = 0;
- for (int i = 0; i < name.length; i++) {
- h += name.charCodeAt(i);
- h &= 0xffffffff;
- h += h << 10;
- h &= 0xffffffff;
- h ^= h >> 6;
- h &= 0xffffffff;
- }
- return h;
- }
-
- int _letterNumber(int x) {
- if (x >= ALPHABET_CHARACTERS) x %= ALPHABET_CHARACTERS;
- if (x < 26) return $a + x;
- return $A + x - 26;
- }
-
- int _alphaNumericNumber(int x) {
- if (x >= ALPHANUMERIC_CHARACTERS) x %= ALPHANUMERIC_CHARACTERS;
- if (x < 26) return $a + x;
- if (x < 52) return $A + x - 26;
- return $0 + x - 52;
- }
-
-}
« no previous file with comments | « lib/compiler/implementation/js_backend/js_backend.dart ('k') | lib/compiler/implementation/js_backend/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698