From 83dc60912007a84c7529b4503c9dfd431322322e Mon Sep 17 00:00:00 2001 From: Dorian Taylor Date: Wed, 9 Jan 2019 17:05:16 -0800 Subject: [PATCH] fix to #121; memoized uri_canonical (cleaned up) --- lib/HTTP/Request.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/HTTP/Request.pm b/lib/HTTP/Request.pm index 0dbb66d6..d2c89d34 100644 --- a/lib/HTTP/Request.pm +++ b/lib/HTTP/Request.pm @@ -92,7 +92,17 @@ sub uri sub uri_canonical { my $self = shift; - return $self->{'_uri_canonical'} ||= $self->{'_uri'}->canonical; + + my $uri = $self->{_uri}; + + if (defined (my $canon = $self->{_uri_canonical})) { + # early bailout if these are the exact same string; try to use + # the cheapest comparison method possible + return $canon if $$canon eq $$uri; + } + + # otherwise we need to refresh the memoized value + $self->{_uri_canonical} = $uri->canonical; }