Performance update using object and array literals

The object and array literals are faster than the 'new' keyword.
This commit is contained in:
Wilson Silva
2012-10-09 15:42:56 +01:00
parent 6f0a965817
commit 0966767ae0
21 changed files with 49 additions and 49 deletions

View File

@@ -56,7 +56,7 @@ package alternativa.engine3d.animation {
/**
* @private
*/
private var states:Object = new Object();
private var states:Object = {};
// private var datasList:BlendedData;
/**

View File

@@ -26,8 +26,8 @@ package alternativa.engine3d.animation {
public var transform:TransformKey = new TransformKey();
public var transformWeightSum:Number = 0;
public var numbers:Object = new Object();
public var numberWeightSums:Object = new Object();
public var numbers:Object = {};
public var numberWeightSums:Object = {};
public function AnimationState() {

View File

@@ -777,7 +777,7 @@ public class Camera3D extends Object3D {
*/
public var debug:Boolean = false;
private var debugSet:Object = new Object();
private var debugSet:Object = {};
/**
* Adds an object or a class to list of debug drawing.

View File

@@ -767,10 +767,10 @@ package alternativa.engine3d.core {
if (listener == null) throw new TypeError("Parameter listener must be non-null.");
var listeners:Object;
if (useCapture) {
if (captureListeners == null) captureListeners = new Object();
if (captureListeners == null) captureListeners = {};
listeners = captureListeners;
} else {
if (bubbleListeners == null) bubbleListeners = new Object();
if (bubbleListeners == null) bubbleListeners = {};
listeners = bubbleListeners;
}
var vector:Vector.<Function> = listeners[type];

View File

@@ -737,7 +737,7 @@ package alternativa.engine3d.loaders {
var byteArray:ByteArray = buffer.byteBuffer;
byteArray.endian = Endian.LITTLE_ENDIAN;
var offset:int = 0;
var attributes:Array = new Array();
var attributes:Array = [];
var jointsOffset:int = 0;
for (var k:int = 0; k < buffer.attributes.length; k++) {
var attr:int;

View File

@@ -150,7 +150,7 @@ package alternativa.engine3d.loaders {
private function parseObject(chunkInfo:ChunkInfo):void {
// Create list of objects, if it need.
if (objectDatas == null) {
objectDatas = new Object();
objectDatas = {};
}
// Create object data
var object:ObjectData = new ObjectData();
@@ -274,7 +274,7 @@ package alternativa.engine3d.loaders {
private function parseSurface(object:ObjectData):void {
// Create list of surfaces, if it need.
if (object.surfaces == null) {
object.surfaces = new Object();
object.surfaces = {};
}
// Name of surface and number of faces.
var sur:String = getString(data.position);
@@ -451,7 +451,7 @@ package alternativa.engine3d.loaders {
private function parseMaterialName(material:MaterialData):void {
// Create list of materials, if it need
if (materialDatas == null) {
materialDatas = new Object();
materialDatas = {};
}
// Get name of material
material.name = getString(data.position);

View File

@@ -61,8 +61,8 @@ package alternativa.engine3d.loaders {
private var fillMaterial:FillMaterial;
public function ParserMaterial() {
textures = new Object();
colors = new Object();
textures = {};
colors = {};
}
/**

View File

@@ -49,9 +49,9 @@ package alternativa.engine3d.loaders {
*/
public var context:Context3D;
private var textures:Object = new Object();
private var bitmapDatas:Object = new Object();
private var byteArrays:Object = new Object();
private var textures:Object = {};
private var bitmapDatas:Object = {};
private var byteArrays:Object = {};
private var currentBitmapDatas:Vector.<BitmapData>;
private var currentUrl:String;
@@ -131,8 +131,8 @@ package alternativa.engine3d.loaders {
if (resources != null) {
throw new Error("Cannot clean while loading");
}
textures = new Object();
bitmapDatas = new Object();
textures = {};
bitmapDatas = {};
}
/**
@@ -142,11 +142,11 @@ package alternativa.engine3d.loaders {
if (resources != null) {
throw new Error("Cannot clean while loading");
}
textures = new Object();
textures = {};
for each (var b:BitmapData in bitmapDatas) {
b.dispose();
}
bitmapDatas = new Object();
bitmapDatas = {};
}
/**

View File

@@ -76,8 +76,8 @@ package alternativa.engine3d.loaders.collada {
private function constructStructures():void {
var element:XML;
sources = new Object();
arrays = new Object();
sources = {};
arrays = {};
for each (element in data..source) {
// Collect all <source>. Dictionary <code>arrays</code> is filled at constructors.
var source:DaeSource = new DaeSource(element, this);
@@ -86,7 +86,7 @@ package alternativa.engine3d.loaders.collada {
}
}
lights = new Object();
lights = {};
for each (element in data.library_lights.light) {
// Collect all <image>.
var light:DaeLight = new DaeLight(element, this);
@@ -94,7 +94,7 @@ package alternativa.engine3d.loaders.collada {
lights[light.id] = light;
}
}
images = new Object();
images = {};
for each (element in data.library_images.image) {
// Collect all <image>.
var image:DaeImage = new DaeImage(element, this);
@@ -102,7 +102,7 @@ package alternativa.engine3d.loaders.collada {
images[image.id] = image;
}
}
effects = new Object();
effects = {};
for each (element in data.library_effects.effect) {
// Collect all <effect>. Dictionary <code>images</code> is filled at constructors.
var effect:DaeEffect = new DaeEffect(element, this);
@@ -110,7 +110,7 @@ package alternativa.engine3d.loaders.collada {
effects[effect.id] = effect;
}
}
materials = new Object();
materials = {};
for each (element in data.library_materials.material) {
// Collect all <material>.
var material:DaeMaterial = new DaeMaterial(element, this);
@@ -118,8 +118,8 @@ package alternativa.engine3d.loaders.collada {
materials[material.id] = material;
}
}
geometries = new Object();
vertices = new Object();
geometries = {};
vertices = {};
for each (element in data.library_geometries.geometry) {
// Collect all <geometry>. Dictionary <code>vertices</code> is filled at constructors.
var geom:DaeGeometry = new DaeGeometry(element, this);
@@ -128,7 +128,7 @@ package alternativa.engine3d.loaders.collada {
}
}
controllers = new Object();
controllers = {};
for each (element in data.library_controllers.controller) {
// Collect all <controllers>.
var controller:DaeController = new DaeController(element, this);
@@ -137,7 +137,7 @@ package alternativa.engine3d.loaders.collada {
}
}
nodes = new Object();
nodes = {};
for each (element in data.library_nodes.node) {
// Create only root nodes. Others are created recursively at constructors.
var node:DaeNode = new DaeNode(element, this);
@@ -172,7 +172,7 @@ package alternativa.engine3d.loaders.collada {
private function constructAnimations():void {
var element:XML;
samplers = new Object();
samplers = {};
for each (element in data.library_animations..sampler) {
// Collect all <sampler>.
var sampler:DaeSampler = new DaeSampler(element, this);

View File

@@ -39,7 +39,7 @@ package alternativa.engine3d.loaders.collada {
}
private function parseSetParams():Object {
var params:Object = new Object();
var params:Object = {};
var list:XMLList = data.instance_effect.setparam;
for each (var element:XML in list) {
var param:DaeParam = new DaeParam(element, document);

View File

@@ -143,7 +143,7 @@ package alternativa.engine3d.loaders.collada {
}
private function parseInstanceMaterials(geometry:XML):Object {
var instances:Object = new Object();
var instances:Object = {};
var list:XMLList = geometry.bind_material.technique_common.instance_material;
for (var i:int = 0, count:int = list.length(); i < count; i++) {
var instance:DaeInstanceMaterial = new DaeInstanceMaterial(list[i], document);

View File

@@ -51,7 +51,7 @@ package alternativa.engine3d.materials.compiler {
alternativa3d var _linkedVariables:Object;
// Dictionary of temporary variables at this linker. Key is a name of variable, value is a variable.
private var _localVariables:Object = new Object();
private var _localVariables:Object = {};
// Key - procedure, value - array of strings.
private var _inputParams:Dictionary = new Dictionary();
@@ -61,9 +61,9 @@ package alternativa.engine3d.materials.compiler {
// Counters of variables by types
private var _locals:Vector.<uint> = new Vector.<uint>(6, true);
private var samplers:Object = new Object();
private var samplers:Object = {};
private var _varyings:Object = new Object();
private var _varyings:Object = {};
/**
* Creates a new Linker instance.
@@ -81,8 +81,8 @@ package alternativa.engine3d.materials.compiler {
data = null;
_locals[0] = _locals[1] = _locals[2] = _locals[3] = _locals[4] = _locals[5] = 0;
procedures.length = 0;
_varyings = new Object();
samplers = new Object();
_varyings = {};
samplers = {};
commandsCount = 0;
slotsCount = 0;
@@ -218,7 +218,7 @@ package alternativa.engine3d.materials.compiler {
if (data != null) return;
var v:Variable;
var variables:Object = _linkedVariables = new Object();
var variables:Object = _linkedVariables = {};
var p:Procedure;
var i:int, j:int;
var nv:Variable;

View File

@@ -179,7 +179,7 @@ package alternativa.engine3d.objects {
if (geometry == null) {
geometry = new Geometry(4);
var attributes:Array = new Array();
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;

View File

@@ -105,7 +105,7 @@ package alternativa.engine3d.objects {
var attributesLengths:Vector.<int> = new Vector.<int>(numAttributes, true);
var numMeshes:Number = collectAttributes(root, attributesDict, attributesLengths);
var attributes:Array = new Array();
var attributes:Array = [];
var i:int;
for (i = 0; i < numAttributes; i++) {

View File

@@ -99,7 +99,7 @@ package alternativa.engine3d.objects {
geometry = new Geometry(24);
var attributes:Array = new Array();
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;

View File

@@ -214,7 +214,7 @@ package alternativa.engine3d.objects {
if (geometry == null) {
geometry = new Geometry(4);
var attributes:Array = new Array();
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;

View File

@@ -187,7 +187,7 @@ package alternativa.engine3d.primitives {
// Set bounds
geometry = new Geometry();
geometry._indices = indices;
var attributes:Array = new Array;
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;

View File

@@ -267,7 +267,7 @@ package alternativa.engine3d.primitives {
geometry = new Geometry();
geometry._indices = indices;
var attributes:Array = new Array();
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;

View File

@@ -100,7 +100,7 @@ package alternativa.engine3d.primitives {
// Set bounds
geometry = new Geometry();
geometry._indices = indices;
var attributes:Array = new Array;
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;

View File

@@ -35,7 +35,7 @@ package alternativa.engine3d.resources {
*
* @example This code creates stream on properties: x,y,z,u,v and forms a triangle by three vertices.
* <listing version="3.0">
* var attributes:Array = new Array();
* var attributes:Array = [];
* attributes[0] = VertexAttributes.POSITION;
* attributes[1] = VertexAttributes.POSITION;
* attributes[2] = VertexAttributes.POSITION;
@@ -146,7 +146,7 @@ package alternativa.engine3d.resources {
*/
public function calculateNormals():void {
if (!hasAttribute(VertexAttributes.POSITION)) throw new Error("Vertices positions is required to calculate normals");
var normals:Array = new Array();
var normals:Array = [];
var positionsStream:VertexStream = _attributesStreams[VertexAttributes.POSITION];
var positionsData:ByteArray = positionsStream.data;
var positionsOffset:int = _attributesOffsets[VertexAttributes.POSITION]*4;
@@ -283,7 +283,7 @@ package alternativa.engine3d.resources {
if (!hasAttribute(VertexAttributes.NORMAL)) throw new Error("Vertices normals is required to calculate tangents, call calculateNormals first");
if (!hasAttribute(VertexAttributes.TEXCOORDS[uvChannel])) throw new Error("Specified uv channel does not exist in geometry");
var tangents:Array = new Array();
var tangents:Array = [];
var positionsStream:VertexStream = _attributesStreams[VertexAttributes.POSITION];
var positionsData:ByteArray = positionsStream.data;

View File

@@ -230,7 +230,7 @@ package alternativa.engine3d.shadows {
var geometry:Geometry = new Geometry(4);
mesh.geometry = geometry;
var attributes:Array = new Array();
var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION;