<commit_before>package lime.app;


import haxe.macro.Context;
import haxe.macro.Expr;


class Event<T> {
	
	
	@:noCompletion public var listeners:Array<T>;
	@:noCompletion public var repeat:Array<Bool>;
	
	private var priorities:Array<Int>;
	
	
	public function new () {
		
		listeners = new Array<T> ();
		priorities = new Array<Int> ();
		repeat = new Array<Bool> ();
		
	}
	
	
	public function add (listener:T, once:Bool = false, priority:Int = 0):Void {
		
		for (i in 0...priorities.length) {
			
			if (priority > priorities[i]) {
				
				listeners.insert (i, listener);
				priorities.insert (i, priority);
				repeat.insert (i, !once);
				return;
				
			}
			
		}
		
		listeners.push (listener);
		priorities.push (priority);
		repeat.push (!once);
		
	}
	
	
	macro public function dispatch (ethis:Expr, args:Array<Expr>) {
		
		return macro {
			
			var listeners = $ethis.listeners;
			var repeat = $ethis.repeat;
			var length = listeners.length;
			var i = 0;
			
			while (i < length) {
				
				listeners[i] ($a{args});
				
				if (!repeat[i]) {
					
					$ethis.remove (listeners[i]);
					length--;
					
				} else {
					
					i++;
					
				}
				
			}
			
		}
		
	}
	
	
	public function remove (listener:T):Void {
		
		var index = listeners.indexOf (listener);
		
		if (index > -1) {
			
			listeners.splice (index, 1);
			priorities.splice (index, 1);
			repeat.splice (index, 1);
			
		}
		
	}
	
	
}<commit_msg>Fix event.remove when called during event.dispatch<commit_after>package lime.app;


import haxe.macro.Context;
import haxe.macro.Expr;


class Event<T> {
	
	
	@:noCompletion public var listeners:Array<T>;
	@:noCompletion public var repeat:Array<Bool>;
	
	private var priorities:Array<Int>;
	
	
	public function new () {
		
		listeners = new Array<T> ();
		priorities = new Array<Int> ();
		repeat = new Array<Bool> ();
		
	}
	
	
	public function add (listener:T, once:Bool = false, priority:Int = 0):Void {
		
		for (i in 0...priorities.length) {
			
			if (priority > priorities[i]) {
				
				listeners.insert (i, listener);
				priorities.insert (i, priority);
				repeat.insert (i, !once);
				return;
				
			}
			
		}
		
		listeners.push (listener);
		priorities.push (priority);
		repeat.push (!once);
		
	}
	
	
	macro public function dispatch (ethis:Expr, args:Array<Expr>) {
		
		return macro {
			
			var listeners = $ethis.listeners;
			var repeat = $ethis.repeat;
			var i = 0;
			
			while (i < listeners.length) {
				
				listeners[i] ($a{args});
				
				if (!repeat[i]) {
					
					$ethis.remove (listeners[i]);
					
				} else {
					
					i++;
					
				}
				
			}
			
		}
		
	}
	
	
	public function remove (listener:T):Void {
		
		var index = listeners.indexOf (listener);
		
		if (index > -1) {
			
			listeners.splice (index, 1);
			priorities.splice (index, 1);
			repeat.splice (index, 1);
			
		}
		
	}
	
	
}
{'fraction_non_alphanumeric': 0.13883089770354906, 'fraction_numerical': 0.0048712595685455815, 'mean_word_length': 2.3391405342624854, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6672518', 'n_tokens_mistral': 1335, 'n_tokens_neox': 951, 'n_words': 229}