On 17/01/2012 03:43, Paul Nema wrote:
> Updating classes, like classstring.cpp, classarray.cpp, etc.
> For function: void ClassString::enumerateProperties( void*,
> Class::PropertyEnumerator& cb ) const
> PropertyEnumerator operator cb is called for each class method.
> Class String has 26 methods, so 26 cb calls (I.E. cb( "methodName",
> false ); etc+25 ) each time this class is instantiated.
> Could be expensive when creating a lot of arrays.
> There are more efficient way to perform this.
> Examples:
> 1. A comma delimited string of methods
Btw, what makes you think that a n-times call to the enumerator callback
is less efficient than
1) Allocating a dynamic string
2) concatenate strings n times into that (which often means reallocating
the string)
3) call the callback once
4) have the callback calling n times findnext(',')
5) creating n times a substring from , to , (with the extra checks for
the last string, and possibly dynamic allocation for each substring if
the string algos are not VERY smart)
6) destroying the string
Also, consider having to call n times next() on the iterator of a map.
Unless it's inlined, you're not gaining much on the callback approach
(also, jumping on the map leaves causes loss of memory locality).
Gian.