Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make EBCDIC a compile-time constant so there's zero overhead (and less

compiled code) in subroutines that test for it. (patch from Tim Bunce)
  • Loading branch information...
commit bc9d42a6f400ff9b95312c2e5b9c4321a230635c 1 parent 63d1a3e
@markstos authored
Showing with 11 additions and 6 deletions.
  1. +4 −0 Changes
  2. +7 −6 lib/CGI/Util.pm
View
4 Changes
@@ -1,4 +1,8 @@
+ [PERFORMANCE]
+ - Make EBCDIC a compile-time constant so there's zero overhead (and less
+ compiled code) in subroutines that test for it. (Tim Bunce)
+
[DOCUMENTATION]
- quit referring to the <link> tag as being "rarely used". (Victor Sanders)
- typo and whitespace fixes (RT#62785, thanks to scop@cpan.org)
View
13 lib/CGI/Util.pm
@@ -1,7 +1,7 @@
package CGI::Util;
use strict;
-use vars qw($VERSION @EXPORT_OK @ISA $EBCDIC @A2E @E2A);
+use vars qw($VERSION @EXPORT_OK @ISA @A2E @E2A);
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(rearrange rearrange_header make_attributes unescape escape
@@ -9,7 +9,8 @@ require Exporter;
$VERSION = '3.51';
-$EBCDIC = "\t" ne "\011";
+use constant EBCDIC => "\t" ne "\011";
+
# (ord('^') == 95) for codepage 1047 as on os390, vmesa
@A2E = (
0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 21, 11, 12, 13, 14, 15,
@@ -48,7 +49,7 @@ $EBCDIC = "\t" ne "\011";
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,179,219,220,217,218,159
);
-if ($EBCDIC && ord('^') == 106) { # as in the BS2000 posix-bc coded character set
+if (EBCDIC && ord('^') == 106) { # as in the BS2000 posix-bc coded character set
$A2E[91] = 187; $A2E[92] = 188; $A2E[94] = 106; $A2E[96] = 74;
$A2E[123] = 251; $A2E[125] = 253; $A2E[126] = 255; $A2E[159] = 95;
$A2E[162] = 176; $A2E[166] = 208; $A2E[168] = 121; $A2E[172] = 186;
@@ -61,7 +62,7 @@ if ($EBCDIC && ord('^') == 106) { # as in the BS2000 posix-bc coded character se
$E2A[221] = 219; $E2A[224] = 217; $E2A[251] = 123; $E2A[253] = 125;
$E2A[255] = 126;
}
-elsif ($EBCDIC && ord('^') == 176) { # as in codepage 037 on os400
+elsif (EBCDIC && ord('^') == 176) { # as in codepage 037 on os400
$A2E[10] = 37; $A2E[91] = 186; $A2E[93] = 187; $A2E[94] = 176;
$A2E[133] = 21; $A2E[168] = 189; $A2E[172] = 95; $A2E[221] = 173;
@@ -210,7 +211,7 @@ sub unescape {
my $todecode = shift;
return undef unless defined($todecode);
$todecode =~ tr/+/ /; # pluses become spaces
- if ($EBCDIC) {
+ if (EBCDIC) {
$todecode =~ s/%([0-9a-fA-F]{2})/chr $A2E[hex($1)]/ge;
} else {
# handle surrogate pairs first -- dankogai
@@ -276,7 +277,7 @@ sub escape {
my $toencode = shift;
return undef unless defined($toencode);
utf8::encode($toencode) if ($] >= 5.008 && utf8::is_utf8($toencode));
- if ($EBCDIC) {
+ if (EBCDIC) {
$toencode=~s/([^a-zA-Z0-9_.~-])/uc sprintf("%%%02x",$E2A[ord($1)])/eg;
} else {
$toencode=~s/([^a-zA-Z0-9_.~-])/uc sprintf("%%%02x",ord($1))/eg;
Please sign in to comment.
Something went wrong with that request. Please try again.