← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:33:55 2022
Reported on Wed Dec 14 15:40:04 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP/Render.pm
StatementsExecuted 29 statements in 1.09ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11137µs99µsYAML::PP::Render::::BEGIN@8YAML::PP::Render::BEGIN@8
11132µs35µsYAML::PP::Parser::::BEGIN@2YAML::PP::Parser::BEGIN@2
11119µs19µsYAML::PP::Render::::render_block_scalarYAML::PP::Render::render_block_scalar
1119µs48µsYAML::PP::Parser::::BEGIN@3YAML::PP::Parser::BEGIN@3
0000s0sYAML::PP::Render::::render_multi_valYAML::PP::Render::render_multi_val
0000s0sYAML::PP::Render::::render_quotedYAML::PP::Render::render_quoted
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# ABSTRACT: YAML::PP Rendering functions
2296µs238µs
# spent 35µs (32+3) within YAML::PP::Parser::BEGIN@2 which was called: # once (32µs+3µs) by YAML::PP::Parser::BEGIN@17 at line 2
use strict;
# spent 35µs making 1 call to YAML::PP::Parser::BEGIN@2 # spent 3µs making 1 call to strict::import
3291µs287µs
# spent 48µs (9+39) within YAML::PP::Parser::BEGIN@3 which was called: # once (9µs+39µs) by YAML::PP::Parser::BEGIN@17 at line 3
use warnings;
# spent 48µs making 1 call to YAML::PP::Parser::BEGIN@3 # spent 39µs making 1 call to warnings::import
4package YAML::PP::Render;
5
610sour $VERSION = '0.035'; # VERSION
7
82876µs2161µs
# spent 99µs (37+62) within YAML::PP::Render::BEGIN@8 which was called: # once (37µs+62µs) by YAML::PP::Parser::BEGIN@17 at line 8
use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0;
# spent 99µs making 1 call to YAML::PP::Render::BEGIN@8 # spent 62µs making 1 call to constant::import
9
10sub render_quoted {
11 my ($self, $style, $lines) = @_;
12
13 my $quoted = '';
14 my $addspace = 0;
15
16 for my $i (0 .. $#$lines) {
17 my $line = $lines->[ $i ];
18 my $value = $line->{value};
19 my $last = $i == $#$lines;
20 my $first = $i == 0;
21 if ($value eq '') {
22 if ($first) {
23 $addspace = 1;
24 }
25 elsif ($last) {
26 $quoted .= ' ' if $addspace;
27 }
28 else {
29 $addspace = 0;
30 $quoted .= "\n";
31 }
32 next;
33 }
34
35 $quoted .= ' ' if $addspace;
36 $addspace = 1;
37 if ($style eq '"') {
38 if ($line->{orig} =~ m/\\$/) {
39 $line->{value} =~ s/\\$//;
40 $value =~ s/\\$//;
41 $addspace = 0;
42 }
43 }
44 $quoted .= $value;
45 }
46 return $quoted;
47}
48
49
# spent 19µs within YAML::PP::Render::render_block_scalar which was called: # once (19µs+0s) by YAML::PP::Lexer::fetch_block at line 611 of YAML/PP/Lexer.pm
sub render_block_scalar {
5011µs my ($self, $block_type, $chomp, $lines) = @_;
51
5210s my ($folded, $keep, $trim);
5313µs if ($block_type eq '>') {
54 $folded = 1;
55 }
5611µs if ($chomp eq '+') {
57 $keep = 1;
58 }
59 elsif ($chomp eq '-') {
60 $trim = 1;
61 }
62
6310s my $string = '';
6412µs if (not $keep) {
65 # remove trailing empty lines
6610s while (@$lines) {
6711µs last if $lines->[-1] ne '';
68 pop @$lines;
69 }
70 }
7110s if ($folded) {
72
73 my $prev = 'START';
74 my $trailing = '';
75 if ($keep) {
76 while (@$lines and $lines->[-1] eq '') {
77 pop @$lines;
78 $trailing .= "\n";
79 }
80 }
81 for my $i (0 .. $#$lines) {
82 my $line = $lines->[ $i ];
83
84 my $type = $line eq ''
85 ? 'EMPTY'
86 : $line =~ m/\A[ \t]/
87 ? 'MORE'
88 : 'CONTENT';
89
90 if ($prev eq 'MORE' and $type eq 'EMPTY') {
91 $type = 'MORE';
92 }
93 elsif ($prev eq 'CONTENT') {
94 if ($type ne 'CONTENT') {
95 $string .= "\n";
96 }
97 elsif ($type eq 'CONTENT') {
98 $string .= ' ';
99 }
100 }
101 elsif ($prev eq 'START' and $type eq 'EMPTY') {
102 $string .= "\n";
103 $type = 'START';
104 }
105 elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') {
106 $string .= "\n";
107 }
108
109 $string .= $line;
110
111 if ($type eq 'MORE' and $i < $#$lines) {
112 $string .= "\n";
113 }
114
115 $prev = $type;
116 }
117 if ($keep) {
118 $string .= $trailing;
119 }
120 $string .= "\n" if @$lines and not $trim;
121 }
122 else {
12313µs for my $i (0 .. $#$lines) {
12453µs $string .= $lines->[ $i ];
12554µs $string .= "\n" if ($i != $#$lines or not $trim);
126 }
127 }
128 TRACE and warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$string], ['string']);
12914µs return $string;
130}
131
132sub render_multi_val {
133 my ($self, $multi) = @_;
134 my $string = '';
135 my $start = 1;
136 for my $line (@$multi) {
137 if (not $start) {
138 if ($line eq '') {
139 $string .= "\n";
140 $start = 1;
141 }
142 else {
143 $string .= " $line";
144 }
145 }
146 else {
147 $string .= $line;
148 $start = 0;
149 }
150 }
151 return $string;
152}
153
154
15514µs1;