Subject: | Reduce memory footprint of Term::ANSIColor with perl522 |
Term::ANSIColor is using 70% more memory than it was in perl514 with perl522.
We can reduce this bloat to less than 10% by avoiding to import
Carp and simplifying some \w regexp as we do not need unicode here.
FYI, the bloat is coming from http://perl5.git.perl.org/perl.git/commitdiff/bcb875216f24899d543c036aebdba0835f8d22e6
View https://rt.perl.org/Public/Bug/Display.html?id=127392 for more details
Subject: | 0001-Reduce-memory-footprint-of-Term-ANSIColor-with-perl5.patch |
From 219ddda181886fa511b4f4a92ca31d7f4d98d25d Mon Sep 17 00:00:00 2001
From: Nicolas R <cpan@eboxr.com>
Date: Fri, 29 Jan 2016 11:25:18 -0600
Subject: [PATCH] Reduce memory footprint of Term::ANSIColor with perl522
Term::ANSIColor is using 70% more memory than it was in perl514.
We can reduce this bloat to less than 10% by avoiding to import
Carp and simplifying some \w regexp.
---
lib/Term/ANSIColor.pm | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/Term/ANSIColor.pm b/lib/Term/ANSIColor.pm
index ace4d47..1f317fe 100644
--- a/lib/Term/ANSIColor.pm
+++ b/lib/Term/ANSIColor.pm
@@ -23,7 +23,6 @@ use 5.006;
use strict;
use warnings;
-use Carp qw(croak);
use Exporter ();
# use Exporter plus @ISA instead of use base for 5.6 compatibility.
@@ -202,6 +201,11 @@ if (exists $ENV{ANSI_COLORS_ALIASES}) {
}
}
+sub croak {
+ require Carp;
+ return Carp::croak( @_ );
+}
+
# Stores the current color stack maintained by PUSHCOLOR and POPCOLOR. This
# is global and therefore not threadsafe.
our @COLORSTACK;
@@ -236,7 +240,9 @@ our @COLORSTACK;
## no critic (ClassHierarchies::ProhibitAutoloading)
## no critic (Subroutines::RequireArgUnpacking)
sub AUTOLOAD {
- my ($sub, $attr) = $AUTOLOAD =~ m{ \A ([\w:]*::([[:upper:]\d_]+)) \z }xms;
+ my ( $sub ) = $AUTOLOAD =~ /^([a-zA-Z0-9:_]+)$/; # untaint
+ my $attr = ( split('::', $sub ) )[-1];
+ undef $attr if ( $attr && $attr !~ qr{^[A-Z0-9_]+$} ) || $sub !~ qr{::};
# Check if we were called with something that doesn't look like an
# attribute.
@@ -501,7 +507,7 @@ sub coloralias {
return $ATTRIBUTES_R{ $ALIASES{$alias} };
}
}
- if ($alias !~ m{ \A [\w._-]+ \z }xms) {
+ if ( $alias !~ m{ \A [a-zA-Z0-9._-]+ \z }xms ) {
croak(qq{Invalid alias name "$alias"});
} elsif ($ATTRIBUTES{$alias}) {
croak(qq{Cannot alias standard color "$alias"});
--
2.7.0