← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:36 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP/Render.pm
StatementsExecuted 29 statements in 684µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11128µs31µsYAML::PP::Parser::::BEGIN@2YAML::PP::Parser::BEGIN@2
11123µs23µsYAML::PP::Render::::render_block_scalarYAML::PP::Render::render_block_scalar
1116µs36µsYAML::PP::Render::::BEGIN@8YAML::PP::Render::BEGIN@8
1114µs32µ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
2232µs234µs
# spent 31µs (28+3) within YAML::PP::Parser::BEGIN@2 which was called: # once (28µs+3µs) by YAML::PP::Parser::BEGIN@17 at line 2
use strict;
# spent 31µs making 1 call to YAML::PP::Parser::BEGIN@2 # spent 3µs making 1 call to strict::import
3250µs260µs
# spent 32µs (4+28) within YAML::PP::Parser::BEGIN@3 which was called: # once (4µs+28µs) by YAML::PP::Parser::BEGIN@17 at line 3
use warnings;
# spent 32µs making 1 call to YAML::PP::Parser::BEGIN@3 # spent 28µs making 1 call to warnings::import
4package YAML::PP::Render;
5
610sour $VERSION = '0.035'; # VERSION
7
82574µs266µs
# spent 36µs (6+30) within YAML::PP::Render::BEGIN@8 which was called: # once (6µs+30µs) by YAML::PP::Parser::BEGIN@17 at line 8
use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0;
# spent 36µs making 1 call to YAML::PP::Render::BEGIN@8 # spent 30µ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 23µs within YAML::PP::Render::render_block_scalar which was called: # once (23µ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
5211µs my ($folded, $keep, $trim);
5311µs if ($block_type eq '>') {
54 $folded = 1;
55 }
5612µs if ($chomp eq '+') {
57 $keep = 1;
58 }
59 elsif ($chomp eq '-') {
60 $trim = 1;
61 }
62
6311µs my $string = '';
6411µs if (not $keep) {
65 # remove trailing empty lines
6611µs while (@$lines) {
6711µs last if $lines->[-1] ne '';
68 pop @$lines;
69 }
70 }
7111µs 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 {
12312µs for my $i (0 .. $#$lines) {
12454µ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']);
12915µ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
15513µs1;