AutoHotkey Community

It is currently May 27th, 2012, 10:41 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: March 10th, 2008, 11:47 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Quote:
The "create" function is needed here, because the process of "creating" is huge time consuming with name validation (in RegEx) and creation of lists.
Why validate the name only on creation?


Because the key names are saved in a list. Later on other commands, first the requested key will be looked up in that list. So no need for other validation process here.

Quote:
Have you noticed that you'll get a run-time error if you attempt to get using an invalid key name?


Yes. One of the main goals with $() are to catch all possible Error Types and write back an Error Code to ErrorLevel.

Another thing is to restrict the names more than AutoHotkey it does. Look at this RegEx for validation:

Code:
RegExMatch(_KeyName, "iS)^[a-zA-Z_][a-zA-Z0-9_]*$")

  • Most reason here is, that a key cannot consist of a number only. Any number is treated as an index (later at get and set commands).
  • Less special chars is future save. May be the user want extract data to convert into other format.
  • Special chars can be used for special cases. For example to guarantee not to interfere with other variables. Take the "$" character for example, it is used to delimit key name and namespace. Also that way they cannot be interfered with local variable names.


There are some things I want to mention. First, here is namespace support integrated. So creating keys in different namespaces are supported; all namespaces comes with own keylists and indexes.
Creating keys in a list should work faster, I think.May be its slower, this should be Benchmarked also.
Also there are some other commands available. And there is another command in planning: deref (like Transform, Deref).

Thx for the tips and your effort.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2008, 6:19 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Tuncay wrote:
Because the key names are saved in a list. Later on other commands, first the requested key will be looked up in that list.
The get command neither validates the key nor uses the key list.
Quote:
Yes. One of the main goals with $() are to catch all possible Error Types and write back an Error Code to ErrorLevel.
By "run-time error" I was referring to an AutoHotkey error dialog, showing a message such as:
Quote:
Error: The following variable name contains an illegal character:
"$_!@"

The current thread will exit.
Clearly, $() does not catch all possible errors. ;)
Quote:
Another thing is to restrict the names more than AutoHotkey it does.
I wasn't questioning validation in general. :)
Quote:
Creating keys in a list should work faster, I think.
It is faster (by perhaps 20%), since each item would otherwise incur the overhead of a function call. I'm not sure how useful it is to initialize every item to the same value, though. :?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2008, 11:34 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Last Changes, Version 0.6
  • some small performance optimizations
  • new commands available: "deref" and "getaddress"

deref-command usage example:
Code:
; Create single key.
key = test
index := $(key, "create", "hello world")
MsgBox Index of '%key%' at 'blank' Namespace is '%index%'.

; Dereference part of strings with the content of matching keys. Multiple
; Namespaces cannot mixed here. Without the third parameter, no deref character
; is needed, to form a match (like the percent signs "%" used by AutoHotkey).
string := $("My computer said 'test' to me.", "deref")
If ErrorLevel = -7
    MsgBox No match was found.
Else
    MsgBox %string%


The get command itself does not validate... lol but look at the if structure. There are some checks before it comes to the get-command. If all checks are ok, then the get-command (and others) sets ErrorLevel to 0 finally.

There are many Return statements, so after Error occurrence, ErrorLevel will be set and return from that point is done. (Exception from this rule is by create lists... where ErrorLevel is raised up 1 one and continue creation.)

Normally I hate multiple Returns ... but this is an optimization reason in speed.

Quote:
By "run-time error" I was referring to an AutoHotkey error dialog, showing a message such as:
Quote:
Error: The following variable name contains an illegal character:
"$_!@"

The current thread will exit.
Clearly, $() does not catch all possible errors. Wink

Ok, in that point your`e right. But if the validation on create process fails, the key is not in list and cannot be found on get or other commands later. Another error is found ("key not found").

By mean of "catching all possible errors" was more to full process of creating and then getting the key, instead of only one command. (Not sure if I explained it correctly...sorry, bad english)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2008, 3:14 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Tuncay wrote:
The get command itself does not validate... lol but look at the if structure. There are some checks before it comes to the get-command. If all checks are ok, then the get-command (and others) sets ErrorLevel to 0 finally.
Run this:
Code:
$("!")
Then tell me again that there is validation before the get command. :roll:
Quote:
By mean of "catching all possible errors" was more to full process of creating and then getting the key, instead of only one command. (Not sure if I explained it correctly...sorry, bad english)
I still don't get it. The "full process of creating and then getting the key" includes "getting the key." It does not validate at that step. In any case, a script may simply use "exist" before "get" when there is doubt, and there won't be a problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2008, 10:40 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Last Changes, Version 0.7
  • small bug removed ("keys"-command returned an additional unneeded new line)
  • bug removed ("deref"-command related): If string contains "@", the string was also divided up into keyname and namespace components.
  • small performance improvements
  • removed creation of lists for performance reason, for simplefieying and because of some problems, it was not fast as thought because the string had to be parsed. Also the benefit is not much, so no need to slow down other commands.
  • Some checks in RegEx for Namespace validation is done. This slows a bit down back.

I think, creation of lists are not fast as I thought/wished. Duo to fact, that parsing of string containing the list is needed.

Source code may irritiate. Its not well documented and there are some dependencies, huge if-structures and multiple Returns.

Here my benchmark results with your script:
Quote:
i: 10000
TIME_CREATE_$: 0.001459
TIME_CREATE_com_store: 0.001533
TIME_CREATE_simple_store: 0.000641
TIME_GET_$: 0.001144
TIME_GET_com_store: 0.001245
TIME_GET_simple_store: 0.000907
TIME_UPDATE_$: 0.001165
TIME_UPDATE_com_store: 0.001506
TIME_UPDATE_simple_store: 0.001218

i: 1000
TIME_CREATE_$: 0.000339
TIME_CREATE_com_store: 0.001563
TIME_CREATE_simple_store: 0.000227
TIME_GET_$: 0.000102
TIME_GET_com_store: 0.001257
TIME_GET_simple_store: 0.000026
TIME_UPDATE_$: 0.000122
TIME_UPDATE_com_store: 0.001499
TIME_UPDATE_simple_store: 0.000151

i: 100
TIME_CREATE_$: 0.000287
TIME_CREATE_com_store: 0.002098
TIME_CREATE_simple_store: 0.000920
TIME_GET_$: 0.000208
TIME_GET_com_store: 0.001258
TIME_GET_simple_store: 0.000005
TIME_UPDATE_$: 0.000054
TIME_UPDATE_com_store: 0.001634
TIME_UPDATE_simple_store: 0.000100


Quote:
Code:
$("!")

Then tell me again that there is validation before the get command. :roll:

Ok I am taking all back. :oops: This is a logical think error of mine. I have forgot to check if that requested keyname is in list, before continue with process. Its a bug ... (correcting this should also slow down a little bit later.)

So I should change to check always with RegEx? But you took me to another way to go now. May be in such a function, so many Error checks are not needed??


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group