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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_backend/renamer.dart

Issue 25713002: - Eliminated the excessive prefixing in the renamer of dart2dart. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/dart_backend/renamer.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/dart_backend/renamer.dart (revision 28152)
+++ sdk/lib/_internal/compiler/implementation/dart_backend/renamer.dart (working copy)
@@ -306,53 +306,53 @@
}
}
+/**
+ * Generates mini ID based on index.
+ * In other words, it converts index to visual representation
+ * as if digits are given characters.
+ */
+String generateMiniId(int index) {
+ const String firstCharAlphabet =
+ r'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+ const String otherCharsAlphabet =
+ r'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$';
+ // It's like converting index in decimal to [chars] radix.
+ StringBuffer resultBuilder = new StringBuffer();
+ if (index < firstCharAlphabet.length) return firstCharAlphabet[index];
+ resultBuilder.write(firstCharAlphabet[index % firstCharAlphabet.length]);
+ index ~/= firstCharAlphabet.length;
+ int length = otherCharsAlphabet.length;
+ while (index >= length) {
+ resultBuilder.write(otherCharsAlphabet[index % length]);
+ index ~/= length;
+ }
+ resultBuilder.write(otherCharsAlphabet[index]);
+ return resultBuilder.toString();
+}
+
+
/** Always tries to return original identifier name unless it is forbidden. */
-String conservativeGenerator(
- String originalName, bool isForbidden(String name)) {
- String newName = originalName;
- while (isForbidden(newName)) {
- newName = 'p_$newName';
+String conservativeGenerator(String name, bool isForbidden(String name)) {
+ String result = name;
+ int index = 0;
+ while (isForbidden(result)) {
+ result = '${generateMiniId(index++)}_$name';
}
- return newName;
+ return result;
}
+
/** Always tries to generate the most compact identifier. */
class MinifyingGenerator {
- static const String firstCharAlphabet =
- r'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- static const String otherCharsAlphabet =
- r'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$';
- int nextIdIndex;
+ int index = 0;
- MinifyingGenerator() : nextIdIndex = 0;
+ MinifyingGenerator();
String generate(bool isForbidden(String name)) {
- String newName;
+ String result;
do {
- newName = getNextId();
- } while(isForbidden(newName));
- return newName;
+ result = generateMiniId(index++);
+ } while(isForbidden(result));
+ return result;
}
-
- /**
- * Generates next mini ID with current index and alphabet.
- * Advances current index.
- * In other words, it converts index to visual representation
- * as if digits are given characters.
- */
- String getNextId() {
- // It's like converting index in decimal to [chars] radix.
- int index = nextIdIndex++;
- StringBuffer resultBuilder = new StringBuffer();
- if (index < firstCharAlphabet.length) return firstCharAlphabet[index];
- resultBuilder.write(firstCharAlphabet[index % firstCharAlphabet.length]);
- index ~/= firstCharAlphabet.length;
- int length = otherCharsAlphabet.length;
- while (index >= length) {
- resultBuilder.write(otherCharsAlphabet[index % length]);
- index ~/= length;
- }
- resultBuilder.write(otherCharsAlphabet[index]);
- return resultBuilder.toString();
- }
-}
+}
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698