remove magic from substr and reduce copying of strings
Apocalypse
8 years ago
0 | 0 |
Revision history for {{$dist->name}}
|
1 | 1 |
|
2 | 2 |
{{$NEXT}}
|
|
3 |
Reduce memory usage and speedup writing large strings by avoiding substr magic
|
3 | 4 |
|
4 | 5 |
1.011 2014-11-14T03:06:48Z UTC
|
5 | 6 |
- Tweak the testsuite thanks to CPANTesters!
|
141 | 141 |
# Write some stuff to the socket
|
142 | 142 |
sub WRITE {
|
143 | 143 |
# Get ourself + buffer + length + offset to write
|
144 | |
my( $self, $buf, $len, $offset ) = @_;
|
|
144 |
my( $self, $len, $offset ) = ( $_[0], $_[2], $_[3] );
|
|
145 |
my $buf = \$_[1]; # don't copy!
|
145 | 146 |
|
146 | 147 |
# Check the status of the SSL handshake
|
147 | 148 |
if ( ! $self->{'ssl_started'} ) {
|
|
158 | 159 |
# seems like the same thing happened to https://www.mail-archive.com/openssl-users@openssl.org/msg28151.html
|
159 | 160 |
$len = 16_384 if $len > 16_384;
|
160 | 161 |
|
161 | |
# We count the number of characters written to the socket
|
162 | |
my $wrote_len = Net::SSLeay::write( $self->{'ssl'}, substr( $buf, $offset, $len ) );
|
|
162 |
# don't trigger substr's magic as it is SLOOOOOOOOW!
|
|
163 |
# see http://www.perlmonks.org/?node_id=732873
|
|
164 |
my $wrote_len = Net::SSLeay::write( $self->{'ssl'}, scalar substr( $$buf, $offset, $len ) );
|
163 | 165 |
|
164 | 166 |
# Did we get an error or number of bytes written?
|
165 | 167 |
# Net::SSLeay::write() returns the number of bytes written, or 0 on unsuccessful
|