← 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/Schema/JSON.pm
StatementsExecuted 165 statements in 1.40ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
14711376µs376µsYAML::PP::Schema::JSON::::_to_intYAML::PP::Schema::JSON::_to_int
11196µs118µsYAML::PP::::BEGIN@1.282 YAML::PP::BEGIN@1.282
1119µs11µsYAML::PP::Schema::JSON::::BEGIN@13YAML::PP::Schema::JSON::BEGIN@13
1118µs41µsYAML::PP::::BEGIN@2.283 YAML::PP::BEGIN@2.283
1118µs37µsYAML::PP::Schema::JSON::::BEGIN@14YAML::PP::Schema::JSON::BEGIN@14
1116µs66µsYAML::PP::Schema::JSON::::BEGIN@7YAML::PP::Schema::JSON::BEGIN@7
1115µs19µsYAML::PP::Schema::JSON::::BEGIN@16YAML::PP::Schema::JSON::BEGIN@16
2212µs2µsYAML::PP::Schema::JSON::::CORE:qrYAML::PP::Schema::JSON::CORE:qr (opcode)
0000s0sYAML::PP::Schema::JSON::::__ANON__[:78]YAML::PP::Schema::JSON::__ANON__[:78]
0000s0sYAML::PP::Schema::JSON::::_to_floatYAML::PP::Schema::JSON::_to_float
0000s0sYAML::PP::Schema::JSON::::registerYAML::PP::Schema::JSON::register
0000s0sYAML::PP::Schema::JSON::::represent_boolYAML::PP::Schema::JSON::represent_bool
0000s0sYAML::PP::Schema::JSON::::represent_floatYAML::PP::Schema::JSON::represent_float
0000s0sYAML::PP::Schema::JSON::::represent_intYAML::PP::Schema::JSON::represent_int
0000s0sYAML::PP::Schema::JSON::::represent_literalYAML::PP::Schema::JSON::represent_literal
0000s0sYAML::PP::Schema::JSON::::represent_undefYAML::PP::Schema::JSON::represent_undef
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1263µs2140µs
# spent 118µs (96+22) within YAML::PP::BEGIN@1.282 which was called: # once (96µs+22µs) by YAML::PP::BEGIN@9 at line 1
use strict;
# spent 118µs making 1 call to YAML::PP::BEGIN@1.282 # spent 22µs making 1 call to strict::import
2237µs274µs
# spent 41µs (8+33) within YAML::PP::BEGIN@2.283 which was called: # once (8µs+33µs) by YAML::PP::BEGIN@9 at line 2
use warnings;
# spent 41µs making 1 call to YAML::PP::BEGIN@2.283 # spent 33µs making 1 call to warnings::import
3package YAML::PP::Schema::JSON;
4
510sour $VERSION = '0.035'; # VERSION
6
7231µs2126µs
# spent 66µs (6+60) within YAML::PP::Schema::JSON::BEGIN@7 which was called: # once (6µs+60µs) by YAML::PP::BEGIN@9 at line 7
use base 'Exporter';
# spent 66µs making 1 call to YAML::PP::Schema::JSON::BEGIN@7 # spent 60µs making 1 call to base::import
811µsour @EXPORT_OK = qw/
9 represent_int represent_float represent_literal represent_bool
10 represent_undef
11/;
12
13217µs213µs
# spent 11µs (9+2) within YAML::PP::Schema::JSON::BEGIN@13 which was called: # once (9µs+2µs) by YAML::PP::BEGIN@9 at line 13
use B;
# spent 11µs making 1 call to YAML::PP::Schema::JSON::BEGIN@13 # spent 2µs making 1 call to B::import
14222µs266µs
# spent 37µs (8+29) within YAML::PP::Schema::JSON::BEGIN@14 which was called: # once (8µs+29µs) by YAML::PP::BEGIN@9 at line 14
use Carp qw/ croak /;
# spent 37µs making 1 call to YAML::PP::Schema::JSON::BEGIN@14 # spent 29µs making 1 call to Exporter::import
15
162579µs233µs
# spent 19µs (5+14) within YAML::PP::Schema::JSON::BEGIN@16 which was called: # once (5µs+14µs) by YAML::PP::BEGIN@9 at line 16
use YAML::PP::Common qw/ YAML_PLAIN_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE /;
# spent 19µs making 1 call to YAML::PP::Schema::JSON::BEGIN@16 # spent 14µs making 1 call to Exporter::import
17
1817µs12µsmy $RE_INT = qr{^(-?(?:0|[1-9][0-9]*))$};
# spent 2µs making 1 call to YAML::PP::Schema::JSON::CORE:qr
1911µs10smy $RE_FLOAT = qr{^(-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)$};
# spent 0s making 1 call to YAML::PP::Schema::JSON::CORE:qr
20
21147642µs
# spent 376µs within YAML::PP::Schema::JSON::_to_int which was called 147 times, avg 3µs/call: # 147 times (376µs+0s) by YAML::PP::Schema::load_scalar at line 342 of YAML/PP/Schema.pm, avg 3µs/call
sub _to_int { 0 + $_[2]->[0] }
22
23# DaTa++ && shmem++
24sub _to_float { unpack F => pack F => $_[2]->[0] }
25
26sub register {
27 my ($self, %args) = @_;
28 my $schema = $args{schema};
29 my $options = $args{options};
30 my $empty_null = 0;
31 for my $opt (@$options) {
32 if ($opt eq 'empty=str') {
33 }
34 elsif ($opt eq 'empty=null') {
35 $empty_null = 1;
36 }
37 else {
38 croak "Invalid option for JSON Schema: '$opt'";
39 }
40 }
41
42 $schema->add_resolver(
43 tag => 'tag:yaml.org,2002:null',
44 match => [ equals => null => undef ],
45 );
46 if ($empty_null) {
47 $schema->add_resolver(
48 tag => 'tag:yaml.org,2002:null',
49 match => [ equals => '' => undef ],
50 implicit => 1,
51 );
52 }
53 else {
54 $schema->add_resolver(
55 tag => 'tag:yaml.org,2002:str',
56 match => [ equals => '' => '' ],
57 implicit => 1,
58 );
59 }
60 $schema->add_resolver(
61 tag => 'tag:yaml.org,2002:bool',
62 match => [ equals => true => $schema->true ],
63 );
64 $schema->add_resolver(
65 tag => 'tag:yaml.org,2002:bool',
66 match => [ equals => false => $schema->false ],
67 );
68 $schema->add_resolver(
69 tag => 'tag:yaml.org,2002:int',
70 match => [ regex => $RE_INT => \&_to_int ],
71 );
72 $schema->add_resolver(
73 tag => 'tag:yaml.org,2002:float',
74 match => [ regex => $RE_FLOAT => \&_to_float ],
75 );
76 $schema->add_resolver(
77 tag => 'tag:yaml.org,2002:str',
78 match => [ all => sub { $_[1]->{value} } ],
79 );
80
81 $schema->add_representer(
82 undefined => \&represent_undef,
83 );
84
85 my $int_flags = B::SVp_IOK;
86 my $float_flags = B::SVp_NOK;
87 $schema->add_representer(
88 flags => $int_flags,
89 code => \&represent_int,
90 );
91 my %special = ( (0+'nan').'' => '.nan', (0+'inf').'' => '.inf', (0-'inf').'' => '-.inf' );
92 $schema->add_representer(
93 flags => $float_flags,
94 code => \&represent_float,
95 );
96 $schema->add_representer(
97 equals => $_,
98 code => \&represent_literal,
99 ) for ("", qw/ true false null /);
100 $schema->add_representer(
101 regex => qr{$RE_INT|$RE_FLOAT},
102 code => \&represent_literal,
103 );
104
105 if ($schema->bool_class) {
106 for my $class (@{ $schema->bool_class }) {
107 $schema->add_representer(
108 class_equals => $class,
109 code => \&represent_bool,
110 );
111 }
112 }
113
114 return;
115}
116
117sub represent_undef {
118 my ($rep, $node) = @_;
119 $node->{style} = YAML_PLAIN_SCALAR_STYLE;
120 $node->{data} = 'null';
121 return 1;
122}
123
124sub represent_literal {
125 my ($rep, $node) = @_;
126 $node->{style} ||= YAML_SINGLE_QUOTED_SCALAR_STYLE;
127 $node->{data} = "$node->{value}";
128 return 1;
129}
130
131
132sub represent_int {
133 my ($rep, $node) = @_;
134 if (int($node->{value}) ne $node->{value}) {
135 return 0;
136 }
137 $node->{style} = YAML_PLAIN_SCALAR_STYLE;
138 $node->{data} = "$node->{value}";
139 return 1;
140}
141
14211µsmy %special = (
143 (0+'nan').'' => '.nan',
144 (0+'inf').'' => '.inf',
145 (0-'inf').'' => '-.inf'
146);
147sub represent_float {
148 my ($rep, $node) = @_;
149 if (exists $special{ $node->{value} }) {
150 $node->{style} = YAML_PLAIN_SCALAR_STYLE;
151 $node->{data} = $special{ $node->{value} };
152 return 1;
153 }
154 if (0.0 + $node->{value} ne $node->{value}) {
155 return 0;
156 }
157 if (int($node->{value}) eq $node->{value} and not $node->{value} =~ m/\./) {
158 $node->{value} .= '.0';
159 }
160 $node->{style} = YAML_PLAIN_SCALAR_STYLE;
161 $node->{data} = "$node->{value}";
162 return 1;
163}
164
165sub represent_bool {
166 my ($rep, $node) = @_;
167 my $string = $node->{value} ? 'true' : 'false';
168 $node->{style} = YAML_PLAIN_SCALAR_STYLE;
169 @{ $node->{items} } = $string;
170 $node->{data} = $string;
171 return 1;
172}
173
17414µs1;
175
176__END__
 
# spent 2µs within YAML::PP::Schema::JSON::CORE:qr which was called 2 times, avg 1µs/call: # once (2µs+0s) by YAML::PP::BEGIN@9 at line 18 # once (0s+0s) by YAML::PP::BEGIN@9 at line 19
sub YAML::PP::Schema::JSON::CORE:qr; # opcode