I made some performance related changes to wml.pm and wml_net.pm.
The change to wml.pm cut my memory use in half, but arrays or chars still suck compared to strings (on the order of x50) when space is important.
This commit is contained in:
parent
b02a37797e
commit
47d564d73a
3 changed files with 20 additions and 7 deletions
|
@ -82,6 +82,13 @@ SVN trunk:
|
|||
the cached campaign, to give perl a chance to release some memory.
|
||||
* Fixed a bug in webtgz.pl where it wasn't handling escaped data in
|
||||
downloaded files.
|
||||
* Updated wml.pm and wml_net.pm to gain some efficiency. wml.pm was changed
|
||||
not to use split, but instead use substr to convert a string to an array.
|
||||
This saved about half the memory usage when using large strings. Arrays
|
||||
are still a pretty bad way to store strings when space is a concern.
|
||||
wml_net.pm was changed to insert into a preallocated string instead of
|
||||
appending in order to avoid lots of reallocations. In theory this should
|
||||
save memory and time, but I didn't benchmark it.
|
||||
* fix untranslated unit create dialog (#4424)
|
||||
* random map generator now uses island_size (#4458)
|
||||
* documentation switch doxygen templates from CVS to SVN and from Savannah to Gna!
|
||||
|
|
|
@ -9,7 +9,7 @@ $wml::max_schema_item_length = 20;
|
|||
|
||||
sub read_literal_word
|
||||
{
|
||||
my $word = "";
|
||||
my $word = '';
|
||||
my ($chars) = @_;
|
||||
while(@$chars) {
|
||||
my $char = shift @$chars;
|
||||
|
@ -63,7 +63,11 @@ sub read_binary
|
|||
my @stack = ($doc);
|
||||
my $cur = $doc;
|
||||
|
||||
my @chars = split //, $input;
|
||||
my $len = length $input;
|
||||
my @chars;
|
||||
for (my $i = 0; $i < $len; $i++) {
|
||||
push @chars, substr($input, $i, 1);
|
||||
}
|
||||
|
||||
while(@chars) {
|
||||
my $char = shift @chars;
|
||||
|
|
|
@ -42,15 +42,17 @@ sub read_packet
|
|||
|
||||
my $len = unpack('N',$buf);
|
||||
|
||||
my $res = '';
|
||||
while($len != length $res) {
|
||||
my $res = "\0" * $len;
|
||||
my $count = 0;
|
||||
while($len > $count) {
|
||||
$buf = '';
|
||||
my $bytes = $len - length $res;
|
||||
my $bytes = $len - $count;
|
||||
read $sock, $buf, $bytes or die "Error reading socket: $!";
|
||||
$res .= $buf;
|
||||
substr($res, $count, length $buf) = $buf;
|
||||
$count += length $buf;
|
||||
}
|
||||
|
||||
$res = substr($res,0,length($res)-1);
|
||||
$res = substr($res,0,$len-1);
|
||||
|
||||
return &wml::read_binary($wml_net::incoming_schemas{$sock},$res);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue