|
From: Cyan O. <cya...@gm...> - 2013-01-18 06:37:55
|
On Jan 17, 2013 8:58 PM, "Porter, Don" <don...@ni...> wrote:
>
>
> Remember that [string length] returns the number of characters in
> the string. That information is not stored anywhere in the Tcl_Obj
struct.
>
> (objPtr->length is in bytes, not chars)
>
> The shimmer happens so that we have someplace to store the computed
> length in chars, so when it's asked for again we don't have to compute it
again.
In a javascript implementation of Tcl that I'm working on, that needs to be
as quick as possible, I took the approach of adding a cache object to each
TclObj, where any code that computes a value based on the TclObj can store
it, associated with some key, so that there can be multiple cached
representations. The cache is cleared when the string rep is invalidated.
This sounds similar to the hydra idea mentioned earlier in the thread, but
lighter.
Dead simple in javascript, but in c the data structures and memory
management might make it cumbersome.
If a similar approach was used for Tcl 9, the char length (or UCS16 rep),
once computed could be stored without shimmering.
Since EIAS, each value has these properties, so perhaps a simpler approach
would be to add then directly as siblings of the bytes and count members,
also lazily computed and invalidated with them.
All that said, I habitually use {$foo eq ""} to test for empty values, so I
haven't been bitten by this particular issue.
Cyan
|