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