[PATCH] preserving message on croak, reduce _waits
Chip Salzenberg
chip at pobox.com
Mon Jan 24 19:10:14 CET 2011
The below patch persuades ->recv to preserve a message unchanged if it
ends with a newline already.
It also, orthogonally, prevents unnecessary calls to _wait. The
performance effect of this change depends on how many of your recvs
wait; in my code, at least, few of them do.
diff --git lib/AnyEvent.pm lib/AnyEvent.pm
index df1f159..a0f7801 100644
--- lib/AnyEvent.pm
+++ lib/AnyEvent.pm
@@ -1765,9 +1765,13 @@ sub _wait {
}
sub recv {
- $_[0]->_wait;
+ $_[0]->_wait unless $_[0]{_ae_sent};
- Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak};
+ if ($_[0]{_ae_croak}) {
+ for ($_[0]{_ae_croak}) {
+ ref() || /\n\z/ ? die $_ : Carp::croak($_)
+ }
+ }
wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0]
}
More information about the anyevent
mailing list