mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
Reduce swarm's optimized code size by 10% (480 to 433K) by replace class names with short ids.
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@65 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
1fae22da51
commit
661e359d74
|
@ -2687,11 +2687,13 @@ public class GenerateJavascriptAST {
|
|||
if (typeParams != null && typeParams.size() != 0) {
|
||||
JsArrayLiteral arr = new JsArrayLiteral();
|
||||
for (Type t : typeParams) {
|
||||
String typeName = "";
|
||||
JsExpression typeName;
|
||||
if (t.getKind() != TypeKind.DYNAMIC) {
|
||||
typeName = getJsName(t.getElement()).getShortIdent();
|
||||
typeName = rtt.getRTTClassId((ClassElement)t.getElement());
|
||||
} else {
|
||||
typeName = string("");
|
||||
}
|
||||
arr.getExpressions().add(string(typeName));
|
||||
arr.getExpressions().add(typeName);
|
||||
}
|
||||
intern.getArguments().add(arr);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ import com.google.dart.compiler.backend.js.ast.JsProgram;
|
|||
import com.google.dart.compiler.backend.js.ast.JsReturn;
|
||||
import com.google.dart.compiler.backend.js.ast.JsScope;
|
||||
import com.google.dart.compiler.backend.js.ast.JsStatement;
|
||||
import com.google.dart.compiler.backend.js.ast.JsStringLiteral;
|
||||
import com.google.dart.compiler.backend.js.ast.JsThisRef;
|
||||
import com.google.dart.compiler.common.SourceInfo;
|
||||
import com.google.dart.compiler.resolver.ClassElement;
|
||||
|
@ -357,10 +358,16 @@ public class RuntimeTypeInjector {
|
|||
globalBlock.getStatements().add(fnDecl.makeStmt());
|
||||
}
|
||||
|
||||
private JsExpression getRTTClassId(ClassElement classElement) {
|
||||
static JsExpression getRTTClassId(TranslationContext translationContext,
|
||||
ClassElement classElement) {
|
||||
JsName classJsName = translationContext.getNames().getName(classElement);
|
||||
JsProgram program = translationContext.getProgram();
|
||||
return program.getStringLiteral(classJsName.getShortIdent());
|
||||
JsStringLiteral clsid = program.getStringLiteral(classJsName.getShortIdent());
|
||||
return call(null, nameref(null, "$cls"), clsid);
|
||||
}
|
||||
|
||||
JsExpression getRTTClassId(ClassElement classElement) {
|
||||
return getRTTClassId(translationContext, classElement);
|
||||
}
|
||||
|
||||
private JsNameRef getRTTLookupMethodName(ClassElement classElement) {
|
||||
|
|
|
@ -19,8 +19,8 @@ function RTT(classkey, typekey, typeargs) {
|
|||
// Add self
|
||||
this.implementedTypes[classkey] = this;
|
||||
// Add Object
|
||||
if (classkey != 'Object') {
|
||||
this.implementedTypes['Object'] = RTT.objectType;
|
||||
if (classkey != $cls('Object')) {
|
||||
this.implementedTypes[$cls('Object')] = RTT.objectType;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ RTT.getNativeTypeInfo = function(value) {
|
|||
* @return {RTT} The RTT information object
|
||||
*/
|
||||
RTT.create = function(name, implementsSupplier, typeArgs) {
|
||||
if (name == "Object") return RTT.objectType;
|
||||
if (name == $cls("Object")) return RTT.objectType;
|
||||
var typekey = RTT.getTypeKey(name, typeArgs);
|
||||
var rtt = RTT.types[typekey];
|
||||
if (rtt) {
|
||||
|
@ -183,18 +183,25 @@ RTT.getTypeArgsFor = function(o, classkey) {
|
|||
// Base types for runtime type information
|
||||
|
||||
/** @type {!RTT} */
|
||||
RTT.objectType = new RTT('Object');
|
||||
RTT.objectType = new RTT($cls('Object'));
|
||||
RTT.objectType.implementedBy = function(o) {return true};
|
||||
RTT.objectType.implementedByType = function(o) {return true};
|
||||
|
||||
/** @type {!RTT} */
|
||||
RTT.dynamicType = new RTT('Dynamic');
|
||||
RTT.dynamicType = new RTT($cls('Dynamic'));
|
||||
RTT.dynamicType.implementedBy = function(o) {return true};
|
||||
RTT.dynamicType.implementedByType = function(o) {return true};
|
||||
|
||||
/** @type {!RTT} */
|
||||
RTT.placeholderType = new RTT('');
|
||||
RTT.placeholderType = new RTT($cls('::'));
|
||||
RTT.placeholderType.implementedBy = function(o) {return true};
|
||||
RTT.placeholderType.implementedByType = function(o) {return true};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} cls
|
||||
* @return {string}
|
||||
* @consistentIdGenerator
|
||||
*/
|
||||
function $cls(cls) {
|
||||
return "cls:" + cls;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue