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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 11428020: Temporarily reverting class field and method name minification. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add regression test Created 8 years, 1 month 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: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
index 12a8d4f4c3cfc97481d4aa974d9e77f961744b38..b2215f84af3fbf5036681b6f00e058bab68c93e3 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -107,51 +107,29 @@ class CodeEmitterTask extends CompilerTask {
String get lazyInitializerName
=> '${namer.ISOLATE}.\$lazy';
- // Property name suffixes. If the accessors are renaming then the format
- // is <accessorName>:<fieldName><suffix>. We use the suffix to know whether
- // to look for the ':' separator in order to avoid doing the indexOf operation
- // on every single property (they are quite rare). None of these characters
- // are legal in an identifier and they are related by bit patterns.
- // setter < 0x3c
- // both = 0x3d
- // getter > 0x3e
- // renaming setter | 0x7c
- // renaming both } 0x7d
- // renaming getter ~ 0x7e
- const SUFFIX_MASK = 0x3f;
- const FIRST_SUFFIX_CODE = 0x3c;
- const SETTER_CODE = 0x3c;
- const GETTER_SETTER_CODE = 0x3d;
- const GETTER_CODE = 0x3e;
- const RENAMING_FLAG = 0x40;
- String needsGetterCode(String variable) => '($variable & 3) > 0';
- String needsSetterCode(String variable) => '($variable & 2) == 0';
- String isRenaming(String variable) => '($variable & $RENAMING_FLAG) != 0';
+ final String GETTER_SUFFIX = "?";
+ final String SETTER_SUFFIX = "!";
+ final String GETTER_SETTER_SUFFIX = "=";
String get generateGetterSetterFunction {
return """
function(field, prototype) {
var len = field.length;
- var lastCharCode = field.charCodeAt(len - 1);
- var needsAccessor = (lastCharCode & $SUFFIX_MASK) >= $FIRST_SUFFIX_CODE;
- if (needsAccessor) {
- var needsGetter = ${needsGetterCode('lastCharCode')};
- var needsSetter = ${needsSetterCode('lastCharCode')};
- var renaming = ${isRenaming('lastCharCode')};
- var accessorName = field = field.substring(0, len - 1);
- if (renaming) {
- var divider = field.indexOf(":");
- accessorName = field.substring(0, divider);
- field = field.substring(divider + 1);
- }
- if (needsGetter) {
- var getterString = "return this." + field + ";";
- prototype["get\$" + accessorName] = new Function(getterString);
- }
- if (needsSetter) {
- var setterString = "this." + field + " = v;";
- prototype["set\$" + accessorName] = new Function("v", setterString);
- }
+ var lastChar = field[len - 1];
+ var needsGetter = lastChar == '$GETTER_SUFFIX' || lastChar == '$GETTER_SETTER_SUFFIX';
+ var needsSetter = lastChar == '$SETTER_SUFFIX' || lastChar == '$GETTER_SETTER_SUFFIX';
+ if (needsGetter || needsSetter) field = field.substring(0, len - 1);
+ if (needsGetter) {
+ var getterString = "return this." + field + ";";
+ """
+ /* The supportsProtoCheck below depends on the getter/setter convention.
+ When changing here, update the protoCheck too. */
+ """
+ prototype["get\$" + field] = new Function(getterString);
+ }
+ if (needsSetter) {
+ var setterString = "this." + field + " = v;";
+ prototype["set\$" + field] = new Function("v", setterString);
}
return field;
}""";
@@ -213,7 +191,7 @@ var $supportsProtoName = false;
var tmp = $defineClassName('c', ['f?'], {}).prototype;
if (tmp.__proto__) {
tmp.__proto__ = {};
- if (typeof tmp.get\$f !== 'undefined') $supportsProtoName = true;
+ if (typeof tmp.get\$f !== "undefined") $supportsProtoName = true;
}
''';
}
@@ -540,7 +518,7 @@ $lazyInitializerLogic
// on A and a typed selector on B could yield the same stub.
Set<String> generatedStubNames = new Set<String>();
if (compiler.enabledFunctionApply
- && member.name == namer.CLOSURE_INVOCATION_NAME) {
+ && member.name == Namer.CLOSURE_INVOCATION_NAME) {
// If [Function.apply] is called, we pessimistically compile all
// possible stubs for this closure.
FunctionSignature signature = member.computeSignature(compiler);
@@ -739,7 +717,6 @@ $lazyInitializerLogic
void visitClassFields(ClassElement classElement,
void addField(Element member,
String name,
- String accessorName,
bool needsGetter,
bool needsSetter,
bool needsCheckedSetter)) {
@@ -775,11 +752,9 @@ $lazyInitializerLogic
if ((isInstantiated && !enclosingClass.isNative())
|| needsGetter
|| needsSetter) {
- String accessorName = isShadowed
+ String fieldName = isShadowed
? namer.shadowedFieldName(member)
: namer.getName(member);
- String fieldName = enclosingClass.isNative() ?
- member.name.slowToString() : accessorName;
bool needsCheckedSetter = false;
if (needsSetter && compiler.enableTypeAssertions
&& canGenerateCheckedSetter(member)) {
@@ -789,7 +764,6 @@ $lazyInitializerLogic
// Getters and setters with suffixes will be generated dynamically.
addField(member,
fieldName,
- accessorName,
needsGetter,
needsSetter,
needsCheckedSetter);
@@ -806,17 +780,13 @@ $lazyInitializerLogic
includeSuperMembers: isInstantiated && !classElement.isNative());
}
- void generateGetter(Element member, String fieldName, String accessorName,
- CodeBuffer buffer) {
- String getterName =
- namer.getterName(member.getLibrary(), new SourceString(accessorName));
+ void generateGetter(Element member, String fieldName, CodeBuffer buffer) {
+ String getterName = namer.getterName(member.getLibrary(), member.name);
buffer.add("$getterName: function() { return this.$fieldName; }");
}
- void generateSetter(Element member, String fieldName, String accessorName,
- CodeBuffer buffer) {
- String setterName =
- namer.setterName(member.getLibrary(), new SourceString(accessorName));
+ void generateSetter(Element member, String fieldName, CodeBuffer buffer) {
+ String setterName = namer.setterName(member.getLibrary(), member.name);
buffer.add("$setterName: function(v) { this.$fieldName = v; }");
}
@@ -833,7 +803,6 @@ $lazyInitializerLogic
void generateCheckedSetter(Element member,
String fieldName,
- String accessorName,
CodeBuffer buffer) {
assert(canGenerateCheckedSetter(member));
DartType type = member.computeType(compiler);
@@ -844,8 +813,7 @@ $lazyInitializerLogic
if (helperElement.computeSignature(compiler).parameterCount != 1) {
additionalArgument = ", '${namer.operatorIs(type.element)}'";
}
- String setterName =
- namer.publicSetterName(new SourceString(accessorName));
+ String setterName = namer.setterName(member.getLibrary(), member.name);
buffer.add("$setterName: function(v) { "
"this.$fieldName = $helperName(v$additionalArgument); }");
}
@@ -860,7 +828,6 @@ $lazyInitializerLogic
bool isFirstField = true;
visitClassFields(classElement, (Element member,
String name,
- String accessorName,
bool needsGetter,
bool needsSetter,
bool needsCheckedSetter) {
@@ -870,19 +837,13 @@ $lazyInitializerLogic
} else {
buffer.add(", ");
}
- buffer.add('"$accessorName');
- int flag = 0;
- if (name != accessorName) {
- buffer.add(':$name');
- assert(needsGetter || needsSetter);
- flag = RENAMING_FLAG;
- }
+ buffer.add('"$name');
if (needsGetter && needsSetter) {
- buffer.addCharCode(GETTER_SETTER_CODE + flag);
+ buffer.add(GETTER_SETTER_SUFFIX);
} else if (needsGetter) {
- buffer.addCharCode(GETTER_CODE + flag);
+ buffer.add(GETTER_SUFFIX);
} else if (needsSetter) {
- buffer.addCharCode(SETTER_CODE + flag);
+ buffer.add(SETTER_SUFFIX);
}
buffer.add('"');
});
@@ -901,7 +862,6 @@ $lazyInitializerLogic
bool emitLeadingComma) {
visitClassFields(classElement, (Element member,
String name,
- String accessorName,
bool needsGetter,
bool needsSetter,
bool needsCheckedSetter) {
@@ -912,7 +872,7 @@ $lazyInitializerLogic
} else {
emitLeadingComma = true;
}
- generateCheckedSetter(member, name, accessorName, buffer);
+ generateCheckedSetter(member, name, buffer);
}
});
}
@@ -1138,7 +1098,7 @@ $lazyInitializerLogic
// create a fake element with the correct name.
// Note: the callElement will not have any enclosingElement.
FunctionElement callElement =
- new ClosureInvocationElement(namer.CLOSURE_INVOCATION_NAME, element);
+ new ClosureInvocationElement(Namer.CLOSURE_INVOCATION_NAME, element);
String staticName = namer.getName(element);
String invocationName = namer.instanceMethodName(callElement);
String fieldAccess = '$isolateProperties.$staticName';
@@ -1236,8 +1196,8 @@ $classesCollector.$mangledName = {'':
// its stubs we simply create a fake element with the correct name.
// Note: the callElement will not have any enclosingElement.
FunctionElement callElement =
- new ClosureInvocationElement(namer.CLOSURE_INVOCATION_NAME, member);
-
+ new ClosureInvocationElement(Namer.CLOSURE_INVOCATION_NAME, member);
+
String invocationName = namer.instanceMethodName(callElement);
List<String> arguments = new List<String>(parameterCount);
for (int i = 0; i < parameterCount; i++) {
@@ -1297,7 +1257,7 @@ $classesCollector.$mangledName = {'':
String invocationName =
namer.instanceMethodInvocationName(memberLibrary, member.name,
selector);
- SourceString callName = namer.CLOSURE_INVOCATION_NAME;
+ SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
String closureCallName =
namer.instanceMethodInvocationName(memberLibrary, callName,
selector);
@@ -1477,14 +1437,11 @@ $classesCollector.$mangledName = {'':
}
String internalName = namer.instanceMethodInvocationName(
selector.library, new SourceString(methodName), selector);
- Element createInvocationMirror =
- compiler.findHelper(const SourceString('createInvocationMirror'));
CodeBuffer buffer = new CodeBuffer();
buffer.add('function($args) {\n');
buffer.add(' return this.$noSuchMethodName('
- '${namer.isolateAccess(createInvocationMirror)}('
- '"$methodName", "$internalName",'
- '$type, [$args], [$argNames]));\n');
+ '\$.createInvocationMirror("$methodName", "$internalName",'
+ ' $type, [$args], [$argNames]));\n');
buffer.add(' }');
return buffer;
}
@@ -1657,10 +1614,10 @@ $mainEnsureGetter
//
// BEGIN invoke [main].
//
-if (typeof document !== 'undefined' && document.readyState != 'complete') {
+if (typeof document != 'undefined' && document.readyState != 'complete') {
document.addEventListener('readystatechange', function () {
if (document.readyState == 'complete') {
- if (typeof dartMainRunner === 'function') {
+ if (typeof dartMainRunner == 'function') {
dartMainRunner(function() { ${mainCall}; });
} else {
${mainCall};
@@ -1668,7 +1625,7 @@ if (typeof document !== 'undefined' && document.readyState != 'complete') {
}
}, false);
} else {
- if (typeof dartMainRunner === 'function') {
+ if (typeof dartMainRunner == 'function') {
dartMainRunner(function() { ${mainCall}; });
} else {
${mainCall};

Powered by Google App Engine
This is Rietveld 408576698