One interesting trick if one wants to objectify all values and at the same time have good performance, is to make some classes "top-wired". Every class can inherit at most one top-wired class, directly or indirectly.
For each instance, there's a field in the header that says which top-wired class (if any) that is inherited by the object's class. The data associated with that class is always stored first in the instance data area, at a fix offset.
Thus, if strings are top-wired, C code can operate on any subclass
if (o->top_wired == GENERIC_STRING_TYPE) { struct generic_string *s = o->data; ... } else error("Expected string"); /* Or generic code using method calls * instead of accessing the internal representation */
which shouldn't be slower than
if (o->type == PIKE_T_STRING) { ... }
/ Niels Möller ()
Previous text:
2003-01-30 18:18: Subject: Re: OpenSSL wrapper vs Pike's SSL (Was: Bz2)
If the builtin strings internally should be treated as objects then we're talking about a much bigger change in terms of necessary code change and compatibility (consider e.g. the use of runtime types and the svalue struct).
Although it isn't designwise as beautiful, I think it's both simpler and more efficient to just tag objects that want to interface as strings, e.g. through inheriting a magic String class which would act mainly as a flag.
/ Martin Stjernholm, Roxen IS