← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:27:00 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Macros/ENCODE.pm
StatementsExecuted 196 statements in 1.68ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1511534µs1.16msFoswiki::::ENCODEFoswiki::ENCODE
11140µs52µsFoswiki::::BEGIN@4.61Foswiki::BEGIN@4.61
11128µs63µsFoswiki::::BEGIN@5.62Foswiki::BEGIN@5.62
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
4261µs264µs
# spent 52µs (40+12) within Foswiki::BEGIN@4.61 which was called: # once (40µs+12µs) by Foswiki::_expandMacroOnTopicRendering at line 4
use strict;
# spent 52µs making 1 call to Foswiki::BEGIN@4.61 # spent 12µs making 1 call to strict::import
52943µs297µs
# spent 63µs (28+35) within Foswiki::BEGIN@5.62 which was called: # once (28µs+35µs) by Foswiki::_expandMacroOnTopicRendering at line 5
use warnings;
# spent 63µs making 1 call to Foswiki::BEGIN@5.62 # spent 34µs making 1 call to warnings::import
61136µ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 1.16ms (534µs+627µs) within Foswiki::ENCODE which was called 15 times, avg 77µs/call: # 15 times (534µs+627µs) by Foswiki::_expandMacroOnTopicRendering at line 3066 of /usr/local/src/github.com/foswiki/core/lib/Foswiki.pm, avg 77µs/call
sub ENCODE {
15165489µs my ( $this, $params ) = @_;
16
17 my $old = $params->{old};
18 my $new = $params->{new};
19 my $type = $params->{type};
20
21 if ( defined $type && ( defined $old || defined $new ) ) {
22 return $this->inlineAlert( 'alerts', 'ENCODE_bad_1' );
23 }
24 if ( defined $old && !defined $new || !defined $old && defined $new ) {
25 return $this->inlineAlert( 'alerts', 'ENCODE_bad_2' );
26 }
27
28 my $text = $params->{_DEFAULT};
29 $text = '' unless defined $text;
30
31 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
59 $type ||= 'url';
60
6115139µs6095µs if ( $type =~ /^entit(y|ies)$/i ) {
# spent 95µs making 60 calls to Foswiki::CORE:match, avg 2µs/call
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)
70 $text =~ s/\"/\\"/go;
71 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 \/>/;
8115532µs return urlEncode($text);
# spent 532µs making 15 calls to Foswiki::urlEncode, avg 36µs/call
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
9519µs1;
96__END__