...but Microsoft's strlcpy implementation overdoes it...
Actually, I don't think the MS C 7.1 library even has a strlcpy in it. I'm using my own that consists simply of:
--aDstSize; // Convert from size to length (caller has ensured that aDstSize > 0).
strncpy(aDst, aSrc, aDstSize);
aDst[aDstSize] = '\0';
The call to strncpy() is where I went wrong: it zero-fills any unused portion of the destination.
It may not be worth creating a hash class just for this function, but if it can be reused elsewhere...
Hashing might get implemented someday for faster lookups of variables and labels. However, it wouldn't be that big of an improvement because:
1) All variables are pre-looked-up when the script launches. No lookups are done at runtime except for dynamic variables (like Array%i%).
2) All lookups use the split binary-search algorithm, which Laszlo suggested when I asked him for an alternative to hashing and trees. This algorithm is quite fast and scales very well (at least up to several million variables).
these micro-optimizations [such as case sensitive comparisons]
I made the change but then realized I had all sorts of new questions for which answers are scarce. For example:
1) Is the strlwr + strcmp strategy
exactly equivalent to str
icmp regardless of setlocale? I suspect the answer is yes, if only because of the high number of people using it.
2) Is strlwr the same as the OS's CharLower? It appears the answer is "no" because strlwr uses setlocale's locale (which is always the C default if you never call setlocale?) but CharLower uses the OS's region as set by the control panel's language/keyboard layout.
3) Does CharLower() always convert the letters A-Z into a-z, regardless of the user's region? Apparently, the answer is so obvious that isn't documented at MSDN or anywhere else I could find. MSDN does offer this little clue, but it's so specific as to be mysterious: "CharLower always maps uppercase I to lowercase I, even when the current language is Turkish or Azeri."
4) If strlwr() is called in the code, there is a slight amount of bloat so I wanted to avoid it. But from the above, it appears that mixing CharLower with strcmp would be a bad practice, even if it happens to work for certain subsets of ANSI characters. CharLower() could be paired up with the OS's CompareString(), but I seem to remember that it's a very poor performer compared to strcmp().
Answers and comments are welcome.