Skip to content

Commit

Permalink
When adding value at end of array use assignment instead of push to i…
Browse files Browse the repository at this point in the history
…mprove performance on mobile. Fixes richardlord#32
  • Loading branch information
richardlord committed Apr 13, 2014
1 parent c5755d3 commit 67401b2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ash/core/Engine.as
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ package ash.core
var entities : Vector.<Entity> = new Vector.<Entity>();
for( var entity : Entity = entityList.head; entity; entity = entity.next )
{
entities.push( entity );
entities[ entities.length ] = entity;
}
return entities;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ package ash.core
var systems : Vector.<System> = new Vector.<System>();
for( var system : System = systemList.head; system; system = system.next )
{
systems.push( system );
systems[ systems.length ] = system;
}
return systems;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ash/core/Entity.as
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ package ash.core
var componentArray : Array = new Array();
for each( var component : * in components )
{
componentArray.push( component );
componentArray[ componentArray.length ] = component;
}
return componentArray;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ash/core/NodeList.as
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ package ash.core
}
var next : Node = end.next;
start.previous = end.next = null;
lists.push( start );
lists[ lists.length ] = start;
start = next;
}
// reassemble it in order
while( lists.length > 1 )
{
lists.push( merge( lists.shift(), lists.shift(), sortFunction ) );
lists[ lists.length ] = merge( lists.shift(), lists.shift(), sortFunction );
}
// find the tail
tail = head = lists[0];
Expand Down
2 changes: 1 addition & 1 deletion src/ash/fsm/EngineState.as
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ package ash.fsm
public function addProvider( provider : ISystemProvider ) : StateSystemMapping
{
var mapping : StateSystemMapping = new StateSystemMapping( this, provider );
providers.push( provider );
providers[ providers.length ] = provider;
return mapping;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/ash/io/enginecodecs/EngineEncoder.as
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ package ash.io.enginecodecs
var encodedComponent : Object = encodeComponent( component );
if( encodedComponent )
{
componentIds.push( encodedComponent );
componentIds[ componentIds.length ] = encodedComponent;
}
}
encodedEntities.push( {
encodedEntities[ encodedEntities.length ] = {
name : entity.name,
components : componentIds
} );
};
}

private function encodeComponent( component : Object ) : uint
Expand All @@ -70,7 +70,7 @@ package ash.io.enginecodecs
{
encoded.id = nextComponentId++;
componentEncodingMap[ component ] = encoded;
encodedComponents.push( encoded );
encodedComponents[ encodedComponents.length ] = encoded;
return encoded.id;
}
return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/ash/io/objectcodecs/ArrayObjectCodec.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package ash.io.objectcodecs
var codec : IObjectCodec;
for each( var value : Object in object )
{
values.push( codecManager.encodeObject( value ) );
values[ values.length ] = codecManager.encodeObject( value );
}
return { type:type, values:values };

Expand All @@ -25,7 +25,7 @@ package ash.io.objectcodecs
var decoded : Object = new type();
for each( var obj : Object in object.values )
{
decoded.push( codecManager.decodeObject( obj ) );
decoded[ decoded.length ] = codecManager.decodeObject( obj );
}
return decoded;
}
Expand All @@ -34,7 +34,7 @@ package ash.io.objectcodecs
{
for each( var obj : Object in object.values )
{
target.push( codecManager.decodeObject( obj ) );
target[ target.length ] = codecManager.decodeObject( obj );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ash/tools/ComponentPool.as
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ package ash.tools
{
var type : Class = component.constructor as Class;
var pool:Array = getPool( type );
pool.push( component );
pool[ pool.length ] = component;
}
}

Expand Down

0 comments on commit 67401b2

Please sign in to comment.