How about defining a one-time IsSet within a class

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
viv
Posts: 219
Joined: 09 Dec 2020, 17:48

How about defining a one-time IsSet within a class

Post by viv » 07 Feb 2023, 01:34

I have defined a class that extends Gui for my own use
It is possible to call to an ini class

Now the question is how to detect IsSet in the scope

I'm saving IsSet(ini) in __New with this.ini

but calling it elsewhere I still had to keep checking IsSet(ini)
According to my logic, I already checked this.ini before calling it
The subsequent IsSet(ini) is completely unnecessary

Some one-time expenses I can still ignore
But every call in OnEvent has to be checked...
Almost every time I change the median value of the gui, will check it again

Is there a way to improve this problem?
Does this expense have an impact, is it negligible?

Code: Select all

g := GuiEx()

class GuiEx extends Gui
{
	__New(opt := unset, title := unset, event := unset, hasIni := true)
	{
		super.__New(opt?, title?, event?)
		this.ini := false
		if hasIni && IsSet(ini) && Type(ini) == "Class"
			this.ini := true
	}
	__AddCtrl(name, opt := "", text := "", var := "")
	{
		varOpt := ""
		if var && (!this.ini || (IsSet(ini) && !ini.HasProp(var)))
			varOpt := " v" var

		ctrl := this.Add(name, opt varOpt, text)

		if this.ini && IsSet(ini) && ini.HasProp(var)
		{
			if name == "Checkbox"
				ctrl.OnEvent("Click", (ctrl, info) => ini.ChangeKey(ctrl.Value, var) )
			; ctrl.OnEvent("Click", (ctrl, info) => IsSet(ini) ? ini.ChangeKey(ctrl.Value, var) : "")
			else
				ctrl.OnEvent("Change", (ctrl, info) =>  ini.ChangeKey(ctrl.Value, var) )
			; ctrl.OnEvent("Change", (ctrl, info) => IsSet(ini) ? ini.ChangeKey(ctrl.Value, var) : "")
		}
		return ctrl
	}
}

viv
Posts: 219
Joined: 09 Dec 2020, 17:48

Re: How about defining a one-time IsSet within a class

Post by viv » 07 Feb 2023, 02:23

Tested 1,000,000 times took about 60ms
It is basically negligible.

Waiting to see if there might be a more elegant way to improve
If not then close it

Code: Select all

now :=  A_TickCount
loop 1000000
	IsSet(ini)
MsgBox(A_TickCount - now)

Post Reply

Return to “Ask for Help (v2)”