enumerator callback question

9 views
Skip to first unread message

Paul Nema

unread,
Jan 16, 2012, 9:43:56 PM1/16/12
to FalconPL
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

2. Pass an array of methods

3. Something else? etc.

Probably a reason for the current design as opposed to the above suggestions.  If so please elaborate.  If not let me know and I explore how to update enumerator.h

Thanks

Giancarlo Niccolai

unread,
Jan 17, 2012, 4:17:14 AM1/17/12
to falc...@googlegroups.com
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.

Reply all
Reply to author
Forward
0 new messages