← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:11 2015

Filename/var/www/foswiki11/lib/Foswiki/Macros/ENCODE.pm
StatementsExecuted 201 statements in 949µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1511134µs134µsFoswiki::::ENCODEFoswiki::ENCODE
11136µs70µsFoswiki::::BEGIN@4.77Foswiki::BEGIN@4.77
11121µs38µsFoswiki::::BEGIN@5.78Foswiki::BEGIN@5.78
0000s0sFoswiki::::_s2dFoswiki::_s2d
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2package Foswiki;
3
4256µs2104µs
# spent 70µs (36+34) within Foswiki::BEGIN@4.77 which was called: # once (36µs+34µs) by Foswiki::_expandMacroOnTopicRendering at line 4
use strict;
# spent 70µs making 1 call to Foswiki::BEGIN@4.77 # spent 34µs making 1 call to strict::import
52719µs255µs
# spent 38µs (21+17) within Foswiki::BEGIN@5.78 which was called: # once (21µs+17µs) by Foswiki::_expandMacroOnTopicRendering at line 5
use warnings;
# spent 38µs making 1 call to Foswiki::BEGIN@5.78 # spent 17µs making 1 call to warnings::import
618µsmy @DIG = map { chr($_) } ( 0 .. 9 );
7
8# Returns a decimal number encoded as a string where each digit is
9# replaced by an unprintable character
10sub _s2d {
11 return join( '', map { chr( int($_) ) } split( '', shift ) );
12}
13
14
# spent 134µs within Foswiki::ENCODE which was called 15 times, avg 9µs/call: # 15 times (134µs+0s) by Foswiki::_expandMacroOnTopicRendering at line 3160 of /var/www/foswiki11/lib/Foswiki.pm, avg 9µs/call
sub ENCODE {
15159µs my ( $this, $params ) = @_;
16
17156µs my $old = $params->{old};
18154µs my $new = $params->{new};
19157µs my $type = $params->{type};
20
21157µs if ( defined $type && ( defined $old || defined $new ) ) {
22 return $this->inlineAlert( 'alerts', 'ENCODE_bad_1' );
23 }
24156µs if ( defined $old && !defined $new || !defined $old && defined $new ) {
25 return $this->inlineAlert( 'alerts', 'ENCODE_bad_2' );
26 }
27
28157µs my $text = $params->{_DEFAULT};
29152µs $text = '' unless defined $text;
30
31152µs if ( defined $old ) {
32 my @old = split( ',', $old );
33 my @new = split( ',', $new );
34 while ( scalar(@new) < scalar(@old) ) {
35 push( @new, '' );
36 }
37
38 # The double loop is to make it behave like tr///. The first loop
39 # locates the tokens to replace, and the second loop subs them.
40 my %toks; # detect repeated tokens
41 for ( my $i = 0 ; $i <= $#old ; $i++ ) {
42 my $e = _s2d($i);
43 my $o = $old[$i];
44 if ( $toks{$o} ) {
45 return $this->inlineAlert( 'alerts', 'ENCODE_bad_3', $o );
46 }
47 $toks{$o} = 1;
48 $o = quotemeta( expandStandardEscapes($o) );
49 $text =~ s/$o/$e/ge;
50 }
51 for ( my $i = 0 ; $i <= $#new ; $i++ ) {
52 my $e = _s2d($i);
53 my $n = expandStandardEscapes( $new[$i] );
54 $text =~ s/$e/$n/g;
55 }
56 return $text;
57 }
58
59153µs $type ||= 'url';
60
611540µs if ( $type =~ /^entit(y|ies)$/i ) {
62 return entityEncode($text);
63 }
64 elsif ( $type =~ /^html$/i ) {
65 return entityEncode( $text, "\n\r" );
66 }
67 elsif ( $type =~ /^quotes?$/i ) {
68
69 # escape quotes with backslash (Bugs:Item3383 fix)
70158µs $text =~ s/\"/\\"/go;
711557µs return $text;
72 }
73 elsif ( $type =~ /^url$/i ) {
74
75 # This is legacy, stretching back to 2001. Checkin comment was:
76 # "Fixed URL encoding". At that time it related to the encoding of
77 # parameters to the "oops" script exclusively. I'm taking it out
78 # because I can't see any situation in which it might have been
79 # used in anger.
80 # $text =~ s/\r*\n\r*/<br \/>/;
81 return urlEncode($text);
82 }
83 elsif ( $type =~ /^(off|none)$/i ) {
84
85 # no encoding
86 return $text;
87 }
88 else { # safe
89 # entity encode ' " < > and %
90 $text =~ s/([<>%'"])/'&#'.ord($1).';'/ge;
91 return $text;
92 }
93}
94
9517µs1;
96__END__