I'm using an old module from CPAN called WinConsole. It is a simple windowing utility for terminals. It works pretty good for me until recently. I decided to profile my application and I discovered that this sub takes up about 1/3 of the processing time. I suspect the substrs at the bottom of the innermost loop to be the problem, but I'm not even 100% sure what that line is doing.
Any suggestions for improvements
I have reformatted the code for clarity, but not changed it's functionality.
#
# makeFullBackBuffer
#
# return a fullscreen attribute and a fullscreen text backbuffers usin
+g all the miniwins' backbuffer content.
sub makeFullBackBuffer
{
my ($self) = @_;
my (@backAtt, @backTxt, $screen, $current, $destCol, $destRow, $act
+ive);
$screen = $self->{'miniwin'}[0];
for (1..$screen->{'height'})
{
push @backTxt, ' ' x $screen->{'width'};
push @backAtt, [(0) x $screen->{'width'}];
}
for $active (reverse @{$self->{'winStack'}})
{
$current=$self->{'miniwin'}[$active];
for my $row (1..$current->{'height'})
{
for my $col (1..$current->{'width'})
{
$destCol = $current->{'colTop'} + $col - 2;
if ($destCol > $screen->{'width'})
{
$destCol = $screen->{'width'};
}
$destRow = $current->{'rowTop'} + $row - 2;
if ($destRow>$screen->{'height'})
{
$destRow = $screen->{'height'};
}
$backAtt[$destRow][$destCol] = $current->{'backAtt'}[$row
+- 1][$col - 1];
$self->{'zBuffer'}[$destRow][$destCol] = $active;
substr($backTxt[$destRow], $destCol, 1) = substr($current-
+>{'backTxt'}[$row - 1],$col - 1, 1);
}
}
}
return \(@backAtt,@backTxt);
}
And before someone mentions it, it does run under strict & warnings without a problem.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.