in reply to inline perl and recursion
I don't know about recurion in XS (C), but you can save a little bit of time by recoding your traversal algorithm to avoid array dereferencing. Something like the following (untested):
# object1: sub depth{ my $self = shift; my $max = 0; foreach my $item ( @{$self->{child}} ) { next if ! defined ($item); my $depth = $item->depth(); $max = $depth if $depth > $max; } $self->{myDepth} = $max+1; return $max+1; }
|
|---|