← 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/Schema/JSON.pm
StatementsExecuted 165 statements in 1.73ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
14711364µs364µsYAML::PP::Schema::JSON::::_to_intYAML::PP::Schema::JSON::_to_int
11130µs35µsYAML::PP::::BEGIN@1.282 YAML::PP::BEGIN@1.282
1118µs10µsYAML::PP::Schema::JSON::::BEGIN@13YAML::PP::Schema::JSON::BEGIN@13
1118µs77µsYAML::PP::Schema::JSON::::BEGIN@7YAML::PP::Schema::JSON::BEGIN@7
1117µs33µsYAML::PP::Schema::JSON::::BEGIN@14YAML::PP::Schema::JSON::BEGIN@14
1117µs26µsYAML::PP::Schema::JSON::::BEGIN@16YAML::PP::Schema::JSON::BEGIN@16
1116µs51µsYAML::PP::::BEGIN@2.283 YAML::PP::BEGIN@2.283
2214µs4µ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
1235µs240µs
# spent 35µs (30+5) within YAML::PP::BEGIN@1.282 which was called: # once (30µs+5µs) by YAML::PP::BEGIN@9 at line 1
use strict;
# spent 35µs making 1 call to YAML::PP::BEGIN@1.282 # spent 5µs making 1 call to strict::import
2258µs296µs
# spent 51µs (6+45) within YAML::PP::BEGIN@2.283 which was called: # once (6µs+45µs) by YAML::PP::BEGIN@9 at line 2
use warnings;
# spent 51µs making 1 call to YAML::PP::BEGIN@2.283 # spent 45µs making 1 call to warnings::import
3package YAML::PP::Schema::JSON;
4
510sour $VERSION = '0.035'; # VERSION
6
7244µs2146µs
# spent 77µs (8+69) within YAML::PP::Schema::JSON::BEGIN@7 which was called: # once (8µs+69µs) by YAML::PP::BEGIN@9 at line 7
use base 'Exporter';
# spent 77µs making 1 call to YAML::PP::Schema::JSON::BEGIN@7 # spent 69µs making 1 call to base::import
816µsour @EXPORT_OK = qw/
9 represent_int represent_float represent_literal represent_bool
10 represent_undef
11/;
12
13228µs212µs
# spent 10µs (8+2) within YAML::PP::Schema::JSON::BEGIN@13 which was called: # once (8µs+2µs) by YAML::PP::BEGIN@9 at line 13
use B;
# spent 10µs making 1 call to YAML::PP::Schema::JSON::BEGIN@13 # spent 2µs making 1 call to B::import
14227µs259µs
# spent 33µs (7+26) within YAML::PP::Schema::JSON::BEGIN@14 which was called: # once (7µs+26µs) by YAML::PP::BEGIN@9 at line 14
use Carp qw/ croak /;
# spent 33µs making 1 call to YAML::PP::Schema::JSON::BEGIN@14 # spent 26µs making 1 call to Exporter::import
15
162960µs245µs
# spent 26µs (7+19) within YAML::PP::Schema::JSON::BEGIN@16 which was called: # once (7µs+19µs) by YAML::PP::BEGIN@9 at line 16
use YAML::PP::Common qw/ YAML_PLAIN_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE /;
# spent 26µs making 1 call to YAML::PP::Schema::JSON::BEGIN@16 # spent 19µs making 1 call to Exporter::import
17
18113µs13µsmy $RE_INT = qr{^(-?(?:0|[1-9][0-9]*))$};
# spent 3µs making 1 call to YAML::PP::Schema::JSON::CORE:qr
1913µs11µsmy $RE_FLOAT = qr{^(-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)$};
# spent 1µs making 1 call to YAML::PP::Schema::JSON::CORE:qr
20
21147549µs
# spent 364µs within YAML::PP::Schema::JSON::_to_int which was called 147 times, avg 2µs/call: # 147 times (364µs+0s) by YAML::PP::Schema::load_scalar at line 342 of YAML/PP/Schema.pm, avg 2µ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
14213µ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
17417µs1;
175
176__END__
 
# spent 4µs within YAML::PP::Schema::JSON::CORE:qr which was called 2 times, avg 2µs/call: # once (3µs+0s) by YAML::PP::BEGIN@9 at line 18 # once (1µs+0s) by YAML::PP::BEGIN@9 at line 19
sub YAML::PP::Schema::JSON::CORE:qr; # opcode