← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Thu Dec 15 15:23:56 2022
Reported on Thu Dec 15 15:27:04 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP/Schema/JSON.pm
StatementsExecuted 163 statements in 1.20ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
14511355µs355µsYAML::PP::Schema::JSON::::_to_intYAML::PP::Schema::JSON::_to_int
11143µs46µsYAML::PP::::BEGIN@1.283 YAML::PP::BEGIN@1.283
11110µs39µsYAML::PP::Schema::JSON::::BEGIN@14YAML::PP::Schema::JSON::BEGIN@14
1117µs9µsYAML::PP::Schema::JSON::::BEGIN@13YAML::PP::Schema::JSON::BEGIN@13
1116µs35µsYAML::PP::::BEGIN@2.284 YAML::PP::BEGIN@2.284
1115µs18µsYAML::PP::Schema::JSON::::BEGIN@16YAML::PP::Schema::JSON::BEGIN@16
1115µs69µsYAML::PP::Schema::JSON::::BEGIN@7YAML::PP::Schema::JSON::BEGIN@7
2213µs3µ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
1229µs249µs
# spent 46µs (43+3) within YAML::PP::BEGIN@1.283 which was called: # once (43µs+3µs) by YAML::PP::BEGIN@9 at line 1
use strict;
# spent 46µs making 1 call to YAML::PP::BEGIN@1.283 # spent 3µs making 1 call to strict::import
2238µs264µs
# spent 35µs (6+29) within YAML::PP::BEGIN@2.284 which was called: # once (6µs+29µs) by YAML::PP::BEGIN@9 at line 2
use warnings;
# spent 35µs making 1 call to YAML::PP::BEGIN@2.284 # spent 29µs making 1 call to warnings::import
3package YAML::PP::Schema::JSON;
4
511µsour $VERSION = '0.035'; # VERSION
6
7239µs2133µs
# spent 69µs (5+64) within YAML::PP::Schema::JSON::BEGIN@7 which was called: # once (5µs+64µs) by YAML::PP::BEGIN@9 at line 7
use base 'Exporter';
# spent 69µs making 1 call to YAML::PP::Schema::JSON::BEGIN@7 # spent 64µ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
13229µs211µs
# spent 9µs (7+2) within YAML::PP::Schema::JSON::BEGIN@13 which was called: # once (7µs+2µs) by YAML::PP::BEGIN@9 at line 13
use B;
# spent 9µs making 1 call to YAML::PP::Schema::JSON::BEGIN@13 # spent 2µs making 1 call to B::import
14220µs268µs
# spent 39µs (10+29) within YAML::PP::Schema::JSON::BEGIN@14 which was called: # once (10µs+29µs) by YAML::PP::BEGIN@9 at line 14
use Carp qw/ croak /;
# spent 39µs making 1 call to YAML::PP::Schema::JSON::BEGIN@14 # spent 29µs making 1 call to Exporter::import
15
162675µs231µs
# spent 18µs (5+13) within YAML::PP::Schema::JSON::BEGIN@16 which was called: # once (5µs+13µs) by YAML::PP::BEGIN@9 at line 16
use YAML::PP::Common qw/ YAML_PLAIN_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE /;
# spent 18µs making 1 call to YAML::PP::Schema::JSON::BEGIN@16 # spent 13µ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
1912µ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
21145349µs
# spent 355µs within YAML::PP::Schema::JSON::_to_int which was called 145 times, avg 2µs/call: # 145 times (355µ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
14212µ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
17415µs1;
175
176__END__
 
# spent 3µs within YAML::PP::Schema::JSON::CORE:qr which was called 2 times, avg 2µs/call: # once (2µ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