Is there any good way to inline method or function calls? Say an attribute on the method or something? I don't know of anything off hand and wanted to know if anyone here knew of anything in particular. There's an example of an inlined function in my newly uploaded ESPPlus::Storage::Record class - the alternative would have me replacing that block with a my $expt_len = $self->expected_length call. The only issue is that its in a speed sensitive section of code - so I'm trying to avoid extra runtime overhead.
Suggestions?
sub body { my $self = shift; if ( exists $self->{'uncompressed'} ) { return $self->{'uncompressed'}; } unless ( exists $self->{'compressed'} ) { confess "Record missing body!"; } my $expt_len; ## START Inline # Inlined the ->expected_length method call here. if ( exists $self->{'expected_length'} ) { $expt_len = $self->{'expected_length'}; } else { if( ${$self->{'header_text'}} =~ /L=(?>[^;]+);/ ) { $expt_len = substr ( ${$self->{'header_text'}}, $-[0] + 2, $+[0] - $-[0] - 3 ); } else { $expt_len = undef; } } ## END Inline $self->{'uncompressed'} = $self->{'uncompress_function'}( $self->{'compressed'}, $expt_len ); my $retr_len = length ${$self->{'uncompressed'}}; unless ( $expt_len == $retr_len ) { confess "Uncompressed record length $retr_len did not match expect +ed " . "length $expt_len for record $self->{record_number}."; } return $self->{'uncompressed'}; }
In reply to Inlining method/function calls? by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |