Skip to content

Commit b3b5fb2

Browse files
AssetManager: Replace Vector With Array
1 parent 0e3929f commit b3b5fb2

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/starling/utils/AssetManager.hx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import haxe.Json;
4141
import haxe.Timer;
4242

4343
import openfl.utils.ByteArray;
44-
import openfl.Vector;
4544

4645
import starling.core.Starling;
4746
import starling.events.Event;
@@ -52,6 +51,7 @@ import starling.textures.AtfData;
5251
import starling.textures.Texture;
5352
import starling.textures.TextureAtlas;
5453
import starling.textures.TextureOptions;
54+
import starling.utils.ArrayUtil;
5555

5656
/** Dispatched when all textures have been restored after a context loss. */
5757
@:meta(Event(name="texturesRestored", type="starling.events.Event"))
@@ -152,7 +152,7 @@ class AssetManager extends EventDispatcher
152152
@:noCompletion private var __bitmapFonts:Map<String, BitmapFont>;
153153

154154
/** helper objects */
155-
private static var sNames:Vector<String> = new Vector<String>();
155+
private static var sNames:Array<String> = new Array<String>();
156156

157157
/** Regex for name / extension extraction from URL. */
158158
private static var NAME_REGEX:EReg = ~/([^\?\/\\]+?)(?:\.([\w\-]+))?(?:\?.*)?$/;
@@ -242,19 +242,24 @@ class AssetManager extends EventDispatcher
242242

243243
/** Returns all textures that start with a certain string, sorted alphabetically
244244
* (especially useful for "MovieClip"). */
245-
public function getTextures(prefix:String="", out:Vector<Texture>=null):Vector<Texture>
245+
public function getTextures(prefix:String="", out:Array<Texture>=null):Array<Texture>
246246
{
247-
if (out == null) out = new Vector<Texture>();
247+
if (out == null) out = new Array<Texture>();
248248

249249
for (name in getTextureNames(prefix, sNames))
250250
out[out.length] = getTexture(name); // avoid 'push'
251251

252-
sNames.length = 0;
252+
#if (haxe_ver >= 4.0)
253+
sNames.resize(0);
254+
#else
255+
ArrayUtil.resize(sNames, 0);
256+
#end
257+
253258
return out;
254259
}
255260

256261
/** Returns all texture names that start with a certain string, sorted alphabetically. */
257-
public function getTextureNames(prefix:String="", out:Vector<String>=null):Vector<String>
262+
public function getTextureNames(prefix:String="", out:Array<String>=null):Array<String>
258263
{
259264
out = getDictionaryKeys(__textures, prefix, out);
260265

@@ -272,8 +277,8 @@ class AssetManager extends EventDispatcher
272277
}
273278

274279
/** Returns all texture atlas names that start with a certain string, sorted alphabetically.
275-
* If you pass an <code>out</code>-vector, the names will be added to that vector. */
276-
public function getTextureAtlasNames(prefix:String="", out:Vector<String>=null):Vector<String>
280+
* If you pass an <code>out</code>-Array, the names will be added to that Array. */
281+
public function getTextureAtlasNames(prefix:String="", out:Array<String>=null):Array<String>
277282
{
278283
return getDictionaryKeys(__atlases, prefix, out);
279284
}
@@ -285,8 +290,8 @@ class AssetManager extends EventDispatcher
285290
}
286291

287292
/** Returns all sound names that start with a certain string, sorted alphabetically.
288-
* If you pass an <code>out</code>-vector, the names will be added to that vector. */
289-
public function getSoundNames(prefix:String="", out:Vector<String>=null):Vector<String>
293+
* If you pass an <code>out</code>-Array, the names will be added to that Array. */
294+
public function getSoundNames(prefix:String="", out:Array<String>=null):Array<String>
290295
{
291296
return getDictionaryKeys(__sounds, prefix, out);
292297
}
@@ -309,8 +314,8 @@ class AssetManager extends EventDispatcher
309314
}
310315

311316
/** Returns all XML names that start with a certain string, sorted alphabetically.
312-
* If you pass an <code>out</code>-vector, the names will be added to that vector. */
313-
public function getXmlNames(prefix:String="", out:Vector<String>=null):Vector<String>
317+
* If you pass an <code>out</code>-Array, the names will be added to that Array. */
318+
public function getXmlNames(prefix:String="", out:Array<String>=null):Array<String>
314319
{
315320
return getDictionaryKeys(__xmls, prefix, out);
316321
}
@@ -323,8 +328,8 @@ class AssetManager extends EventDispatcher
323328
}
324329

325330
/** Returns all object names that start with a certain string, sorted alphabetically.
326-
* If you pass an <code>out</code>-vector, the names will be added to that vector. */
327-
public function getObjectNames(prefix:String="", out:Vector<String>=null):Vector<String>
331+
* If you pass an <code>out</code>-Array, the names will be added to that Array. */
332+
public function getObjectNames(prefix:String="", out:Array<String>=null):Array<String>
328333
{
329334
return getDictionaryKeys(__objects, prefix, out);
330335
}
@@ -336,8 +341,8 @@ class AssetManager extends EventDispatcher
336341
}
337342

338343
/** Returns all byte array names that start with a certain string, sorted alphabetically.
339-
* If you pass an <code>out</code>-vector, the names will be added to that vector. */
340-
public function getByteArrayNames(prefix:String="", out:Vector<String>=null):Vector<String>
344+
* If you pass an <code>out</code>-Array, the names will be added to that Array. */
345+
public function getByteArrayNames(prefix:String="", out:Array<String>=null):Array<String>
341346
{
342347
return getDictionaryKeys(__byteArrays, prefix, out);
343348
}
@@ -349,8 +354,8 @@ class AssetManager extends EventDispatcher
349354
}
350355

351356
/** Returns all bitmap fonts names that start with a certain string, sorted alphabetically.
352-
* If you pass an <code>out</code>-vector, the names will be added to that vector. */
353-
public function getBitmapFontNames(prefix:String="", out:Vector<String>=null):Vector<String>
357+
* If you pass an <code>out</code>-Array, the names will be added to that Array. */
358+
public function getBitmapFontNames(prefix:String="", out:Array<String>=null):Array<String>
354359
{
355360
return getDictionaryKeys(__bitmapFonts, prefix, out);
356361
}
@@ -716,7 +721,7 @@ class AssetManager extends EventDispatcher
716721

717722
var i:Int;
718723
var canceled:Bool = false;
719-
var xmls:Vector<Xml> = new Vector<Xml>();
724+
var xmls:Array<Xml> = new Array<Xml>();
720725
var assetInfos:Array<QueuedAsset> = __queue.copy();
721726
var assetCount:Int = __queue.length;
722727
var assetProgress:Array<Float> = [];
@@ -880,7 +885,7 @@ class AssetManager extends EventDispatcher
880885
}
881886

882887
private function processRawAsset(name:String, rawAsset:Dynamic, options:TextureOptions,
883-
xmls:Vector<Xml>,
888+
xmls:Array<Xml>,
884889
onProgress:Float->Void, onComplete:Void->Void):Void
885890
{
886891
var canceled:Bool = false;
@@ -1329,9 +1334,9 @@ class AssetManager extends EventDispatcher
13291334
}
13301335

13311336
private function getDictionaryKeys(dictionary:Map<String, Dynamic>, prefix:String="",
1332-
out:Vector<String>=null):Vector<String>
1337+
out:Array<String>=null):Array<String>
13331338
{
1334-
if (out == null) out = new Vector<String>();
1339+
if (out == null) out = new Array<String>();
13351340

13361341
for (name in dictionary.keys())
13371342
if (name.indexOf(prefix) == 0)

0 commit comments

Comments
 (0)