Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: sq/JSIL
base: 78fe519262
...
head fork: sq/JSIL
compare: 6b6decdd83
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 03, 2012
K. Gadd kg When creating types, generate the public interface function based on …
…the precise characteristics of the type so that it's more efficient. Improves the performance of the common use case for object construction (MethodSignature.Construct and CreateInstanceOfType are still slow).

Don't use CreateInstanceOfType in struct field initializers anymore since the default ctor should be faster.
179c207
K. Gadd kg More miscellaneous tuning 6b6decd
Showing with 114 additions and 36 deletions.
  1. +102 −32 Libraries/JSIL.Core.js
  2. +12 −4 Libraries/JSIL.XNACore.js
134 Libraries/JSIL.Core.js
View
@@ -1377,9 +1377,7 @@ $jsilcore.$Of$NoInitialize = function () {
var resultTypeObject = JSIL.CloneObject(typeObject);
- resultTypeObject.__PublicInterface__ = result = function GenericType__ctor () {
- return Function.prototype.apply.call(staticClassObject, this, arguments);
- };
+ resultTypeObject.__PublicInterface__ = result = JSIL.MakeTypeConstructor(resultTypeObject);
resultTypeObject.__OpenType__ = typeObject;
result.__Type__ = resultTypeObject;
@@ -1891,9 +1889,9 @@ JSIL.MakeStructFieldInitializer = function (typeObject) {
continue;
}
- body[i] = "target['" + fieldName + "'] = JSIL.CreateInstanceOfType(types[" + i.toString() + "], null);";
+ body[i] = "target['" + fieldName + "'] = new (types[" + i.toString() + "]);";
- types[i] = fieldType;
+ types[i] = fieldType.__PublicInterface__;
}
var rawFunction = JSIL.CreateNamedFunction(
@@ -3089,6 +3087,99 @@ JSIL.MakeTypeAlias = function (sourceAssembly, fullName) {
sourceAssembly.typesByName[fullName] = context.typesByName[fullName];
};
+JSIL.MakeTypeConstructor = function (typeObject) {
+ var openTypeError = function OpenType__ctor () {
+ throw new Error("Cannot construct an instance of an open type");
+ };
+
+ var isStruct = typeObject.__IsStruct__;
+ var sfi = $jsilcore.FunctionNotInitialized;
+ var innerCtor = $jsilcore.FunctionNotInitialized;
+ var ctorToCall = $jsilcore.FunctionNotInitialized;
+
+ var oneTime = function Type__ctor_Once () {
+ JSIL.InitializeType(typeObject);
+
+ typeObject.__StructFieldInitializer__ = sfi = JSIL.MakeStructFieldInitializer(typeObject);
+
+ innerCtor = this._ctor;
+
+ if (typeObject.__IsClosed__ === false) {
+ ctorToCall = openTypeError;
+ } else {
+
+ if (isStruct) {
+ if (sfi !== $jsilcore.FunctionNull) {
+ if (innerCtor) {
+ ctorToCall = function Type__ctor () {
+ sfi(this);
+
+ if (arguments.length === 0)
+ return;
+
+ return innerCtor.apply(this, arguments);
+ };
+
+ } else {
+ ctorToCall = sfi;
+
+ }
+
+ } else {
+ if (innerCtor) {
+ ctorToCall = function Type__ctor () {
+ if (arguments.length !== 0)
+ return innerCtor.apply(this, arguments);
+ };
+
+ } else {
+ ctorToCall = function Type__ctor () {
+ };
+
+ }
+
+ }
+
+ } else {
+ if (sfi !== $jsilcore.FunctionNull) {
+ if (innerCtor) {
+ ctorToCall = function Type__ctor () {
+ sfi(this);
+
+ return innerCtor.apply(this, arguments);
+ };
+
+ } else {
+ ctorToCall = sfi;
+
+ }
+
+ } else {
+ if (innerCtor) {
+ ctorToCall = innerCtor;
+
+ } else {
+ ctorToCall = function Type__ctor () {
+ };
+
+ }
+
+ }
+ }
+ }
+
+ return ctorToCall.apply(this, arguments);
+ };
+
+ ctorToCall = oneTime;
+
+ var result = function Type__ctor_Dispatcher () {
+ return ctorToCall.apply(this, arguments);
+ };
+
+ return result;
+};
+
JSIL.MakeType = function (baseType, fullName, isReferenceType, isPublic, genericArguments, initializer) {
if (typeof (isPublic) === "undefined")
JSIL.Host.error(new Error("Must specify isPublic"));
@@ -3145,29 +3236,7 @@ JSIL.MakeType = function (baseType, fullName, isReferenceType, isPublic, generic
var inited = false;
- var staticClassObject = function Type__ctor () {
- var _typeObject = this.__ThisType__;
-
- if (inited === false) {
- inited = true;
- JSIL.InitializeType(_typeObject);
- }
-
- if (_typeObject.__IsClosed__ === false)
- throw new Error("Cannot construct an instance of an open type");
-
- JSIL.InitializeStructFields(this, _typeObject);
-
- var args = arguments;
- if (args === null)
- args = [];
-
- if (!_typeObject.__IsReferenceType__ && (args.length == 0))
- return;
-
- if (typeof (this._ctor) != "undefined")
- this._ctor.apply(this, args);
- };
+ var staticClassObject = JSIL.MakeTypeConstructor(typeObject);
JSIL.SetValueProperty(staticClassObject, "toString", function TypePublicInterface_ToString () {
return "<" + fullName + " Public Interface>";
@@ -4366,8 +4435,8 @@ JSIL.MethodSignature.prototype.returnType = null;
JSIL.MethodSignature.prototype.argumentTypes = [];
JSIL.MethodSignature.prototype._genericSuffix = null;
JSIL.MethodSignature.prototype._hash = null;
-JSIL.MethodSignature.prototype._lastKeyName = null;
-JSIL.MethodSignature.prototype._lastKey = null;
+JSIL.MethodSignature.prototype._lastKeyName = "<null>";
+JSIL.MethodSignature.prototype._lastKey = "<null>";
Object.defineProperty(JSIL.MethodSignature.prototype, "GenericSuffix", {
configurable: false,
@@ -4385,8 +4454,9 @@ JSIL.MethodSignatureCache = function () {
this._cache = {};
};
JSIL.MethodSignatureCache.prototype.get = function (id, returnType, argumentTypes, genericArgumentNames, context) {
- if (id in this._cache)
- return this._cache[id];
+ var cached = this._cache[id];
+ if (cached)
+ return cached;
if ((typeof (returnType) === "undefined") || (typeof (argumentTypes) === "undefined"))
throw new Error("Signature '" + id + "' not in cache.");
16 Libraries/JSIL.XNACore.js
View
@@ -4214,13 +4214,21 @@ $jsilxna.ClampByte = function (v) {
var $drawDebugRects = false, $drawDebugBoxes = false;
JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.SpriteBatch", function ($) {
- var $canvasDrawImage = function canvasDrawImage (image, sourceX, sourceY, sourceW, sourceH, positionX, positionY, destW, destH) {
- try {
+ if (false) {
+ var $canvasDrawImage = function canvasDrawImage (image, sourceX, sourceY, sourceW, sourceH, positionX, positionY, destW, destH) {
+ try {
+ this.device.context.drawImage(
+ image, sourceX, sourceY, sourceW, sourceH, positionX, positionY, destW, destH
+ );
+ } catch (exc) {
+ console.log("Error calling drawImage with arguments ", Array.prototype.slice.call(arguments), ": ", exc);
+ }
+ }
+ } else {
+ var $canvasDrawImage = function canvasDrawImage (image, sourceX, sourceY, sourceW, sourceH, positionX, positionY, destW, destH) {
this.device.context.drawImage(
image, sourceX, sourceY, sourceW, sourceH, positionX, positionY, destW, destH
);
- } catch (exc) {
- console.log("Error calling drawImage with arguments ", Array.prototype.slice.call(arguments), ": ", exc);
}
}

No commit comments for this range

Something went wrong with that request. Please try again.