← Index
NYTProf Performance Profile   « line view »
For Makefile.PL
  Run on Sun Mar 1 16:04:44 2015
Reported on Sun Mar 1 16:09:02 2015

FilenameC:/tmp64ng/perl/lib/Text/ParseWords.pm
StatementsExecuted 999 statements in 15.6ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1442115.6ms15.6msText::ParseWords::::CORE:substText::ParseWords::CORE:subst (opcode)
1110s0sText::ParseWords::::BEGIN@133Text::ParseWords::BEGIN@133
1110s0sText::ParseWords::::BEGIN@3Text::ParseWords::BEGIN@3
1110s0sText::ParseWords::::BEGIN@62Text::ParseWords::BEGIN@62
1110s0sText::ParseWords::::BEGIN@8Text::ParseWords::BEGIN@8
72110s0sText::ParseWords::::CORE:regcompText::ParseWords::CORE:regcomp (opcode)
0000s0sText::ParseWords::::nested_quotewordsText::ParseWords::nested_quotewords
0000s0sText::ParseWords::::old_shellwordsText::ParseWords::old_shellwords
6110s15.6msText::ParseWords::::parse_lineText::ParseWords::parse_line
6210s15.6msText::ParseWords::::quotewordsText::ParseWords::quotewords
0000s0sText::ParseWords::::shellwordsText::ParseWords::shellwords
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Text::ParseWords;
2
320s20s
# spent 0s within Text::ParseWords::BEGIN@3 which was called: # once (0s+0s) by ExtUtils::Liblist::Kid::_win32_ext at line 3
use strict;
# spent 0s making 1 call to Text::ParseWords::BEGIN@3 # spent 0s making 1 call to strict::import
410srequire 5.006;
510sour $VERSION = "3.29";
6
7
820s20s
# spent 0s within Text::ParseWords::BEGIN@8 which was called: # once (0s+0s) by ExtUtils::Liblist::Kid::_win32_ext at line 8
use Exporter;
# spent 0s making 1 call to Exporter::import # spent 0s making 1 call to Text::ParseWords::BEGIN@8
910sour @ISA = qw(Exporter);
1010sour @EXPORT = qw(shellwords quotewords nested_quotewords parse_line);
1110sour @EXPORT_OK = qw(old_shellwords);
1210sour $PERL_SINGLE_QUOTE;
13
14
15sub shellwords {
16 my (@lines) = @_;
17 my @allwords;
18
19 foreach my $line (@lines) {
20 $line =~ s/^\s+//;
21 my @words = parse_line('\s+', 0, $line);
22 pop @words if (@words and !defined $words[-1]);
23 return() unless (@words || !length($line));
24 push(@allwords, @words);
25 }
26 return(@allwords);
27}
28
- -
31
# spent 15.6ms (0s+15.6) within Text::ParseWords::quotewords which was called 6 times, avg 2.60ms/call: # 3 times (0s+15.6ms) by ExtUtils::Liblist::Kid::_win32_default_search_paths at line 382 of ExtUtils/Liblist/Kid.pm, avg 5.20ms/call # 3 times (0s+0s) by ExtUtils::Liblist::Kid::_win32_make_lib_search_list at line 371 of ExtUtils/Liblist/Kid.pm, avg 0s/call
sub quotewords {
3260s my($delim, $keep, @lines) = @_;
3360s my($line, @words, @allwords);
34
3560s foreach $line (@lines) {
3660s615.6ms @words = parse_line($delim, $keep, $line);
# spent 15.6ms making 6 calls to Text::ParseWords::parse_line, avg 2.60ms/call
3760s return() unless (@words || !length($line));
3860s push(@allwords, @words);
39 }
4060s return(@allwords);
41}
42
- -
45sub nested_quotewords {
46 my($delim, $keep, @lines) = @_;
47 my($i, @allwords);
48
49 for ($i = 0; $i < @lines; $i++) {
50 @{$allwords[$i]} = parse_line($delim, $keep, $lines[$i]);
51 return() unless (@{$allwords[$i]} || !length($lines[$i]));
52 }
53 return(@allwords);
54}
55
- -
58
# spent 15.6ms (0s+15.6) within Text::ParseWords::parse_line which was called 6 times, avg 2.60ms/call: # 6 times (0s+15.6ms) by Text::ParseWords::quotewords at line 36, avg 2.60ms/call
sub parse_line {
5960s my($delimiter, $keep, $line) = @_;
6060s my($word, @pieces);
61
6220s20s
# spent 0s within Text::ParseWords::BEGIN@62 which was called: # once (0s+0s) by ExtUtils::Liblist::Kid::_win32_ext at line 62
no warnings 'uninitialized'; # we will be testing undef strings
# spent 0s making 1 call to Text::ParseWords::BEGIN@62 # spent 0s making 1 call to warnings::unimport
63
6460s while (length($line)) {
65 # This pattern is optimised to be stack conservative on older perls.
66 # Do not refactor without being careful and testing it on very long strings.
67 # See Perl bug #42980 for an example of a stack busting input.
687215.6ms14415.6ms $line =~ s/^
# spent 15.6ms making 72 calls to Text::ParseWords::CORE:subst, avg 217µs/call # spent 0s making 72 calls to Text::ParseWords::CORE:regcomp, avg 0s/call
69 (?:
70 # double quoted string
71 (") # $quote
72 ((?>[^\\"]*(?:\\.[^\\"]*)*))" # $quoted
73 | # --OR--
74 # singe quoted string
75 (') # $quote
76 ((?>[^\\']*(?:\\.[^\\']*)*))' # $quoted
77 | # --OR--
78 # unquoted string
79 ( # $unquoted
80 (?:\\.|[^\\"'])*?
81 )
82 # followed by
83 ( # $delim
84 \Z(?!\n) # EOL
85 | # --OR--
86 (?-x:$delimiter) # delimiter
87 | # --OR--
88 (?!^)(?=["']) # a quote
89 )
90 )//xs or return; # extended layout
91720s my ($quote, $quoted, $unquoted, $delim) = (($1 ? ($1,$2) : ($3,$4)), $5, $6);
92
93
94720s return() unless( defined($quote) || length($unquoted) || length($delim));
95
96720s if ($keep) {
97 $quoted = "$quote$quoted$quote";
98 }
99 else {
100720s720s $unquoted =~ s/\\(.)/$1/sg;
# spent 0s making 72 calls to Text::ParseWords::CORE:subst, avg 0s/call
101720s if (defined $quote) {
102 $quoted =~ s/\\(.)/$1/sg if ($quote eq '"');
103 $quoted =~ s/\\([\\'])/$1/g if ( $PERL_SINGLE_QUOTE && $quote eq "'");
104 }
105 }
106720s $word .= substr($line, 0, 0); # leave results tainted
107720s $word .= defined $quote ? $quoted : $unquoted;
108
109720s if (length($delim)) {
110660s push(@pieces, $word);
111660s push(@pieces, $delim) if ($keep eq 'delimiters');
112660s undef $word;
113 }
114720s if (!length($line)) {
115 push(@pieces, $word);
116 }
117 }
11860s return(@pieces);
119}
120
- -
123sub old_shellwords {
124
125 # Usage:
126 # use ParseWords;
127 # @words = old_shellwords($line);
128 # or
129 # @words = old_shellwords(@lines);
130 # or
131 # @words = old_shellwords(); # defaults to $_ (and clobbers it)
132
13320s20s
# spent 0s within Text::ParseWords::BEGIN@133 which was called: # once (0s+0s) by ExtUtils::Liblist::Kid::_win32_ext at line 133
no warnings 'uninitialized'; # we will be testing undef strings
# spent 0s making 1 call to Text::ParseWords::BEGIN@133 # spent 0s making 1 call to warnings::unimport
134 local *_ = \join('', @_) if @_;
135 my (@words, $snippet);
136
137 s/\A\s+//;
138 while ($_ ne '') {
139 my $field = substr($_, 0, 0); # leave results tainted
140 for (;;) {
141 if (s/\A"(([^"\\]|\\.)*)"//s) {
142 ($snippet = $1) =~ s#\\(.)#$1#sg;
143 }
144 elsif (/\A"/) {
145 require Carp;
146 Carp::carp("Unmatched double quote: $_");
147 return();
148 }
149 elsif (s/\A'(([^'\\]|\\.)*)'//s) {
150 ($snippet = $1) =~ s#\\(.)#$1#sg;
151 }
152 elsif (/\A'/) {
153 require Carp;
154 Carp::carp("Unmatched single quote: $_");
155 return();
156 }
157 elsif (s/\A\\(.?)//s) {
158 $snippet = $1;
159 }
160 elsif (s/\A([^\s\\'"]+)//) {
161 $snippet = $1;
162 }
163 else {
164 s/\A\s+//;
165 last;
166 }
167 $field .= $snippet;
168 }
169 push(@words, $field);
170 }
171 return @words;
172}
173
17410s1;
175
176__END__
 
# spent 0s within Text::ParseWords::CORE:regcomp which was called 72 times, avg 0s/call: # 72 times (0s+0s) by Text::ParseWords::parse_line at line 68, avg 0s/call
sub Text::ParseWords::CORE:regcomp; # opcode
# spent 15.6ms within Text::ParseWords::CORE:subst which was called 144 times, avg 108µs/call: # 72 times (15.6ms+0s) by Text::ParseWords::parse_line at line 68, avg 217µs/call # 72 times (0s+0s) by Text::ParseWords::parse_line at line 100, avg 0s/call
sub Text::ParseWords::CORE:subst; # opcode