Isn't there already a lookup for the variable itself that's O(log(n))? It ought to be possible to device a system where the accessor functions internally are named identically as the identifier they cover, and then there's just some flag test to find out whether it's an accessor function pair or a real variable. If that means that no real variable can be named the same, I wouldn't regard it as a problem (rather the contrary, actually).
/ Martin Stjernholm, Roxen IS
Previous text:
2003-12-22 09:26: Subject: C#-like properties
accessor-functions would be nice, but they would incur significant overhead. In particular, looking up the `-> and `->= functions can be done in O(1) time, but looking up a function with a varying name currently takes O(log(n)) time (where n is the number of functions in the class) In a language with static binding, this is of course not a problem. Unfortunately pike only has static binding within objects, as soon as you call another object, dynamic binding is used.
A workaround for this problem would be to convert the method lookup function to use a hash-table instead of a binary seek. That way, method lookups would *always* be O(1), and while accessor functions would still incur some overhead, it wouln't be nearly as bad. (Also, converting the lookup function would make it possible to get rid of a function lookup cache, which could be a very nice net gain.)
The drawback is that hash tables use a bit more memory than binary seeks, but I don't think that's a major issue in this day and age. Especially since memory usage is linear to the total number of functions in the program, not the number of instances.
/ Fredrik (Naranek) Hubinette (Real Build Master)