← Index
NYTProf Performance Profile   « line view »
For /Users/brian/bin/perls/cpan5.26.1
  Run on Sat Dec 30 01:41:10 2017
Reported on Sat Dec 30 01:44:14 2017

Filename/usr/local/perls/perl-5.26.1/lib/5.26.1/Text/ParseWords.pm
StatementsExecuted 108 statements in 508µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
311210µs419µsText::ParseWords::::parse_lineText::ParseWords::parse_line
611147µs147µsText::ParseWords::::CORE:regcompText::ParseWords::CORE:regcomp (opcode)
31194µs522µsText::ParseWords::::shellwordsText::ParseWords::shellwords
153171µs71µsText::ParseWords::::CORE:substText::ParseWords::CORE:subst (opcode)
0000s0sText::ParseWords::::BEGINText::ParseWords::BEGIN
0000s0sText::ParseWords::::nested_quotewordsText::ParseWords::nested_quotewords
0000s0sText::ParseWords::::old_shellwordsText::ParseWords::old_shellwords
0000s0sText::ParseWords::::quotewordsText::ParseWords::quotewords
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
3use strict;
4require 5.006;
5our $VERSION = "3.30";
6
7
8use Exporter;
9our @ISA = qw(Exporter);
10our @EXPORT = qw(shellwords quotewords nested_quotewords parse_line);
11our @EXPORT_OK = qw(old_shellwords);
12our $PERL_SINGLE_QUOTE;
13
14
15
# spent 522µs (94+428) within Text::ParseWords::shellwords which was called 3 times, avg 174µs/call: # 3 times (94µs+428µs) by CPAN::shell at line 367 of CPAN.pm, avg 174µs/call
sub shellwords {
1639µs my (@lines) = @_;
1731µs my @allwords;
18
1938µs foreach my $line (@lines) {
20332µs39µs $line =~ s/^\s+//;
# spent 9µs making 3 calls to Text::ParseWords::CORE:subst, avg 3µs/call
21318µs3419µs my @words = parse_line('\s+', 0, $line);
# spent 419µs making 3 calls to Text::ParseWords::parse_line, avg 140µs/call
2235µs pop @words if (@words and !defined $words[-1]);
2331µs return() unless (@words || !length($line));
2437µs push(@allwords, @words);
25 }
26311µs return(@allwords);
27}
28
- -
31sub quotewords {
32 my($delim, $keep, @lines) = @_;
33 my($line, @words, @allwords);
34
35 foreach $line (@lines) {
36 @words = parse_line($delim, $keep, $line);
37 return() unless (@words || !length($line));
38 push(@allwords, @words);
39 }
40 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 419µs (210+209) within Text::ParseWords::parse_line which was called 3 times, avg 140µs/call: # 3 times (210µs+209µs) by Text::ParseWords::shellwords at line 21, avg 140µs/call
sub parse_line {
5937µs my($delimiter, $keep, $line) = @_;
6032µs my($word, @pieces);
61
62 no warnings 'uninitialized'; # we will be testing undef strings
63
6433µs 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.
686254µs12202µs $line =~ s/^
# spent 147µs making 6 calls to Text::ParseWords::CORE:regcomp, avg 24µs/call # spent 55µs making 6 calls to Text::ParseWords::CORE:subst, avg 9µs/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
91638µs my ($quote, $quoted, $unquoted, $delim) = (($1 ? ($1,$2) : ($3,$4)), $5, $6);
92
93
9466µs return() unless( defined($quote) || length($unquoted) || length($delim));
95
9662µs if ($keep) {
97 $quoted = "$quote$quoted$quote";
98 }
99 else {
100622µs67µs $unquoted =~ s/\\(.)/$1/sg;
# spent 7µs making 6 calls to Text::ParseWords::CORE:subst, avg 1µs/call
10163µs if (defined $quote) {
102 $quoted =~ s/\\(.)/$1/sg if ($quote eq '"');
103 $quoted =~ s/\\([\\'])/$1/g if ( $PERL_SINGLE_QUOTE && $quote eq "'");
104 }
105 }
106612µs $word .= substr($line, 0, 0); # leave results tainted
10766µs $word .= defined $quote ? $quoted : $unquoted;
108
10963µs if (length($delim)) {
11036µs push(@pieces, $word);
11135µs push(@pieces, $delim) if ($keep eq 'delimiters');
11232µs undef $word;
113 }
114628µs if (!length($line)) {
115 push(@pieces, $word);
116 }
117 }
118317µs 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
133 no warnings 'uninitialized'; # we will be testing undef strings
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
1741;
175
176__END__
 
# spent 147µs within Text::ParseWords::CORE:regcomp which was called 6 times, avg 24µs/call: # 6 times (147µs+0s) by Text::ParseWords::parse_line at line 68, avg 24µs/call
sub Text::ParseWords::CORE:regcomp; # opcode
# spent 71µs within Text::ParseWords::CORE:subst which was called 15 times, avg 5µs/call: # 6 times (55µs+0s) by Text::ParseWords::parse_line at line 68, avg 9µs/call # 6 times (7µs+0s) by Text::ParseWords::parse_line at line 100, avg 1µs/call # 3 times (9µs+0s) by Text::ParseWords::shellwords at line 20, avg 3µs/call
sub Text::ParseWords::CORE:subst; # opcode