Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Class/MOP/Method/Inlined.pm |
Statements | Executed 210 statements in 924µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
32 | 2 | 1 | 398µs | 2.20ms | can_be_inlined | Class::MOP::Method::Inlined::
1 | 1 | 1 | 8µs | 8µs | BEGIN@2 | Class::MOP::Method::Inlined::
1 | 1 | 1 | 6µs | 62µs | BEGIN@15 | Class::MOP::Method::Inlined::
1 | 1 | 1 | 6µs | 37µs | BEGIN@13 | Class::MOP::Method::Inlined::
1 | 1 | 1 | 6µs | 9µs | BEGIN@10 | Class::MOP::Method::Inlined::
1 | 1 | 1 | 6µs | 26µs | BEGIN@12 | Class::MOP::Method::Inlined::
1 | 1 | 1 | 6µs | 17µs | BEGIN@9 | Class::MOP::Method::Inlined::
0 | 0 | 0 | 0s | 0s | _uninlined_body | Class::MOP::Method::Inlined::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::MOP::Method::Inlined; | ||||
2 | # spent 8µs within Class::MOP::Method::Inlined::BEGIN@2 which was called:
# once (8µs+0s) by base::import at line 4 | ||||
3 | 1 | 4µs | $Class::MOP::Method::Inlined::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 33µs | 1 | 8µs | } # spent 8µs making 1 call to Class::MOP::Method::Inlined::BEGIN@2 |
5 | { | ||||
6 | 2 | 900ns | $Class::MOP::Method::Inlined::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 21µs | 2 | 28µs | # spent 17µs (6+11) within Class::MOP::Method::Inlined::BEGIN@9 which was called:
# once (6µs+11µs) by base::import at line 9 # spent 17µs making 1 call to Class::MOP::Method::Inlined::BEGIN@9
# spent 11µs making 1 call to strict::import |
10 | 2 | 22µs | 2 | 12µs | # spent 9µs (6+3) within Class::MOP::Method::Inlined::BEGIN@10 which was called:
# once (6µs+3µs) by base::import at line 10 # spent 9µs making 1 call to Class::MOP::Method::Inlined::BEGIN@10
# spent 3µs making 1 call to warnings::import |
11 | |||||
12 | 2 | 28µs | 2 | 47µs | # spent 26µs (6+21) within Class::MOP::Method::Inlined::BEGIN@12 which was called:
# once (6µs+21µs) by base::import at line 12 # spent 26µs making 1 call to Class::MOP::Method::Inlined::BEGIN@12
# spent 21µs making 1 call to Exporter::import |
13 | 2 | 23µs | 2 | 67µs | # spent 37µs (6+31) within Class::MOP::Method::Inlined::BEGIN@13 which was called:
# once (6µs+31µs) by base::import at line 13 # spent 37µs making 1 call to Class::MOP::Method::Inlined::BEGIN@13
# spent 31µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 348µs | 2 | 62µs | # spent 62µs (6+56) within Class::MOP::Method::Inlined::BEGIN@15 which was called:
# once (6µs+56µs) by base::import at line 15 # spent 62µs making 1 call to Class::MOP::Method::Inlined::BEGIN@15
# spent 56µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 56µs |
16 | |||||
17 | sub _uninlined_body { | ||||
18 | my $self = shift; | ||||
19 | |||||
20 | my $super_method | ||||
21 | = $self->associated_metaclass->find_next_method_by_name( $self->name ) | ||||
22 | or return; | ||||
23 | |||||
24 | if ( $super_method->isa(__PACKAGE__) ) { | ||||
25 | return $super_method->_uninlined_body; | ||||
26 | } | ||||
27 | else { | ||||
28 | return $super_method->body; | ||||
29 | } | ||||
30 | } | ||||
31 | |||||
32 | # spent 2.20ms (398µs+1.80) within Class::MOP::Method::Inlined::can_be_inlined which was called 32 times, avg 69µs/call:
# 31 times (381µs+1.72ms) by Class::MOP::Class::_inline_constructor at line 1451 of Class/MOP/Class.pm, avg 68µs/call
# once (17µs+84µs) by Class::MOP::Class::_inline_destructor at line 1489 of Class/MOP/Class.pm | ||||
33 | 32 | 5µs | my $self = shift; | ||
34 | 32 | 23µs | 32 | 26µs | my $metaclass = $self->associated_metaclass; # spent 25µs making 30 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 820ns/call
# spent 2µs making 2 calls to Class::MOP::Method::associated_metaclass, avg 950ns/call |
35 | 32 | 77µs | 32 | 23µs | my $class = $metaclass->name; # spent 23µs making 32 calls to Class::MOP::Package::name, avg 725ns/call |
36 | |||||
37 | # If we don't find an inherited method, this is a rather weird | ||||
38 | # case where we have no method in the inheritance chain even | ||||
39 | # though we're expecting one to be there | ||||
40 | 32 | 93µs | 64 | 1.69ms | my $inherited_method # spent 1.67ms making 32 calls to Class::MOP::Class::find_next_method_by_name, avg 52µs/call
# spent 16µs making 32 calls to Class::MOP::Method::name, avg 491ns/call |
41 | = $metaclass->find_next_method_by_name( $self->name ); | ||||
42 | |||||
43 | 32 | 91µs | 30 | 41µs | if ( $inherited_method # spent 41µs making 30 calls to UNIVERSAL::isa, avg 1µs/call |
44 | && $inherited_method->isa('Class::MOP::Method::Wrapped') ) { | ||||
45 | warn "Not inlining '" | ||||
46 | . $self->name | ||||
47 | . "' for $class since it " | ||||
48 | . "has method modifiers which would be lost if it were inlined\n"; | ||||
49 | |||||
50 | return 0; | ||||
51 | } | ||||
52 | |||||
53 | 32 | 131µs | 32 | 20µs | my $expected_class = $self->_expected_method_class # spent 20µs making 32 calls to Class::MOP::Method::Inlined::_expected_method_class, avg 631ns/call |
54 | or return 1; | ||||
55 | |||||
56 | # if we are shadowing a method we first verify that it is | ||||
57 | # compatible with the definition we are replacing it with | ||||
58 | 1 | 7µs | 2 | 1µs | my $expected_method = $expected_class->can( $self->name ); # spent 1µs making 1 call to UNIVERSAL::can
# spent 400ns making 1 call to Class::MOP::Method::name |
59 | |||||
60 | 1 | 200ns | if ( ! $expected_method ) { | ||
61 | warn "Not inlining '" | ||||
62 | . $self->name | ||||
63 | . "' for $class since ${expected_class}::" | ||||
64 | . $self->name | ||||
65 | . " is not defined\n"; | ||||
66 | |||||
67 | return 0; | ||||
68 | } | ||||
69 | |||||
70 | 1 | 7µs | 2 | 2µs | my $actual_method = $class->can( $self->name ) # spent 2µs making 1 call to UNIVERSAL::can
# spent 400ns making 1 call to Class::MOP::Method::name |
71 | or return 1; | ||||
72 | |||||
73 | # the method is what we wanted (probably Moose::Object::new) | ||||
74 | 1 | 7µs | 2 | 1µs | return 1 # spent 1µs making 2 calls to Scalar::Util::refaddr, avg 550ns/call |
75 | if refaddr($expected_method) == refaddr($actual_method); | ||||
76 | |||||
77 | # otherwise we have to check that the actual method is an inlined | ||||
78 | # version of what we're expecting | ||||
79 | if ( $inherited_method->isa(__PACKAGE__) ) { | ||||
80 | if ( $inherited_method->_uninlined_body | ||||
81 | && refaddr( $inherited_method->_uninlined_body ) | ||||
82 | == refaddr($expected_method) ) { | ||||
83 | return 1; | ||||
84 | } | ||||
85 | } | ||||
86 | elsif ( refaddr( $inherited_method->body ) | ||||
87 | == refaddr($expected_method) ) { | ||||
88 | return 1; | ||||
89 | } | ||||
90 | |||||
91 | my $warning | ||||
92 | = "Not inlining '" | ||||
93 | . $self->name | ||||
94 | . "' for $class since it is not" | ||||
95 | . " inheriting the default ${expected_class}::" | ||||
96 | . $self->name . "\n"; | ||||
97 | |||||
98 | if ( $self->isa("Class::MOP::Method::Constructor") ) { | ||||
99 | |||||
100 | # FIXME kludge, refactor warning generation to a method | ||||
101 | $warning | ||||
102 | .= "If you are certain you don't need to inline your" | ||||
103 | . " constructor, specify inline_constructor => 0 in your" | ||||
104 | . " call to $class->meta->make_immutable\n"; | ||||
105 | } | ||||
106 | |||||
107 | warn $warning; | ||||
108 | |||||
109 | return 0; | ||||
110 | } | ||||
111 | |||||
112 | 1 | 3µs | 1; | ||
113 | |||||
114 | # ABSTRACT: Method base class for methods which have been inlined | ||||
115 | |||||
116 | __END__ |