From cbd1249e5c245ee605c32c6cdbdc1e26f92643d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 15 Mar 2011 17:53:14 +0100 Subject: [PATCH] Iconv Handle cachen. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Text::Iconv ist sloppy programmiert und leakt bei FCGI Anwendungen etwa 1MB pro grossem Request. Das entsprechende Ticket [1] ist 3 Jahre alt, und es ist nicht damit zu rechnen, dass das in nächster Zeit behoben wird. Die Handle werden jetzt sortiert gecachet und im Klassenraum vorgehalten, so dass der Overhead für die Iconv Objekte abschätzbar bei 4,4kb pro Encoding Kombination ist. [1] https://rt.cpan.org/Public/Bug/Display.html?id=31101 --- SL/Iconv.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SL/Iconv.pm b/SL/Iconv.pm index 9fb296e41..c2f2247ea 100644 --- a/SL/Iconv.pm +++ b/SL/Iconv.pm @@ -6,7 +6,7 @@ use Text::Iconv; use SL::Common; -use vars qw(%converters); +my %converters; use strict; @@ -23,7 +23,7 @@ sub get_converter { my ($from_charset, $to_charset) = @_; my $index = join $SUBSCRIPT_SEPARATOR, $from_charset, $to_charset; - $converters{$index} ||= SL::Iconv->new($from_charset, $to_charset); + $converters{$index} ||= Text::Iconv->new($from_charset, $to_charset) || die; return $converters{$index}; } @@ -44,8 +44,8 @@ sub _convert { my $self = shift; my $text = shift; - $text = $self->{handle}->convert($text) if !$self->{to_is_utf8} || !Encode::is_utf8($text); - $text = decode("utf-8-strict", $text) if $self->{to_is_utf8} && !Encode::is_utf8($text); + $text = convert($self->{from}, $self->{to}, $text) if !$self->{to_is_utf8} || !Encode::is_utf8($text); + $text = decode("utf-8-strict", $text) if $self->{to_is_utf8} && !Encode::is_utf8($text); return $text; } @@ -56,7 +56,6 @@ sub _init { $self->{to} = shift; $self->{to} = 'UTF-8' if lc $self->{to} eq 'unicode'; $self->{to_is_utf8} = $self->{to} =~ m/^utf-?8$/i; - $self->{handle} = Text::Iconv->new($self->{from}, $self->{to}) || die; return $self; } -- 2.20.1