Skip to content

Commit

Permalink
Touch: Replace Vector with Array
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimensionscape committed Jul 10, 2024
1 parent 56ca012 commit 725ae8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/starling/events/EventDispatcher.hx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EventDispatcher {

if (index != -1) {
if (__eventStack.indexOf(type) == -1) {
listeners.removeAt(index);
listeners.splice(index, 1);
} else {
var restListeners:Array<Function> = listeners.slice(0, index);

Expand Down
24 changes: 16 additions & 8 deletions src/starling/events/Touch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package starling.events;

import openfl.geom.Matrix;
import openfl.geom.Point;
import openfl.Vector;

import starling.display.DisplayObject;
import starling.utils.Pool;
Expand Down Expand Up @@ -54,7 +53,7 @@ class Touch
@:noCompletion private var __width:Float;
@:noCompletion private var __height:Float;
@:noCompletion private var __cancelled:Bool;
@:noCompletion private var __bubbleChain:Vector<EventDispatcher>;
@:noCompletion private var __bubbleChain:Array<EventDispatcher>;

/** Helper object. */
private static var sHelperPoint:Point = new Point();
Expand Down Expand Up @@ -92,7 +91,7 @@ class Touch
__tapCount = 0;
__phase = TouchPhase.HOVER;
__pressure = __width = __height = 1.0;
__bubbleChain = new Vector<EventDispatcher>();
__bubbleChain = new Array<EventDispatcher>();
__timestamp = __startTimestamp = -1;
}

Expand Down Expand Up @@ -204,15 +203,24 @@ class Touch
var length:Int = 1;
var element:DisplayObject = __target;

__bubbleChain.length = 1;
#if (haxe_ver >= 4.0)
__bubbleChain.resize(1);
#else
ArrayUtil.resize(__bubbleChain, 1);
#end

__bubbleChain[0] = element;

while ((element = element.parent) != null)
__bubbleChain[length++] = element;
}
else
{
__bubbleChain.length = 0;
#if (haxe_ver >= 4.0)
__bubbleChain.resize(0);
#else
ArrayUtil.resize(__bubbleChain, 0);
#end
}
}

Expand Down Expand Up @@ -371,9 +379,9 @@ class Touch
}

/** @private */
@:allow(starling) private var bubbleChain(get, never):Vector<EventDispatcher>;
private function get_bubbleChain():Vector<EventDispatcher>
@:allow(starling) private var bubbleChain(get, never):Array<EventDispatcher>;
private function get_bubbleChain():Array<EventDispatcher>
{
return __bubbleChain.concat();
return __bubbleChain.copy();
}
}

0 comments on commit 725ae8d

Please sign in to comment.