| Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Class/MOP/Method/Inlined.pm |
| Statements | Executed 446 statements in 2.58ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 62 | 2 | 1 | 1.60ms | 6.90ms | Class::MOP::Method::Inlined::can_be_inlined |
| 1 | 1 | 1 | 19µs | 37µs | Class::MOP::Method::Inlined::BEGIN@4 |
| 1 | 1 | 1 | 12µs | 56µs | Class::MOP::Method::Inlined::BEGIN@9 |
| 1 | 1 | 1 | 11µs | 18µs | Class::MOP::Method::Inlined::BEGIN@5 |
| 1 | 1 | 1 | 11µs | 44µs | Class::MOP::Method::Inlined::BEGIN@7 |
| 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 | 1µs | our $VERSION = '2.1403'; | ||
| 3 | |||||
| 4 | 2 | 36µs | 2 | 56µs | # spent 37µs (19+19) within Class::MOP::Method::Inlined::BEGIN@4 which was called:
# once (19µs+19µs) by parent::import at line 4 # spent 37µs making 1 call to Class::MOP::Method::Inlined::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 2 | 37µs | 2 | 24µs | # spent 18µs (11+6) within Class::MOP::Method::Inlined::BEGIN@5 which was called:
# once (11µs+6µs) by parent::import at line 5 # spent 18µs making 1 call to Class::MOP::Method::Inlined::BEGIN@5
# spent 6µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 2 | 37µs | 2 | 77µs | # spent 44µs (11+33) within Class::MOP::Method::Inlined::BEGIN@7 which was called:
# once (11µs+33µs) by parent::import at line 7 # spent 44µs making 1 call to Class::MOP::Method::Inlined::BEGIN@7
# spent 33µs making 1 call to Exporter::import |
| 8 | |||||
| 9 | 2 | 577µs | 2 | 56µs | # spent 56µs (12+44) within Class::MOP::Method::Inlined::BEGIN@9 which was called:
# once (12µs+44µs) by parent::import at line 9 # spent 56µs making 1 call to Class::MOP::Method::Inlined::BEGIN@9
# spent 44µs making 1 call to parent::import, recursion: max depth 1, sum of overlapping time 44µ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 6.90ms (1.60+5.30) within Class::MOP::Method::Inlined::can_be_inlined which was called 62 times, avg 111µs/call:
# 46 times (1.32ms+4.43ms) by Class::MOP::Class::_inline_constructor at line 1466 of Class/MOP/Class.pm, avg 125µs/call
# 16 times (273µs+872µs) by Class::MOP::Class::_inline_destructor at line 1508 of Class/MOP/Class.pm, avg 72µs/call | ||||
| 27 | 62 | 27µs | my $self = shift; | ||
| 28 | 62 | 96µs | 62 | 89µs | my $metaclass = $self->associated_metaclass; # spent 55µs making 32 calls to Class::MOP::Method::associated_metaclass, avg 2µs/call
# spent 34µs making 30 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 1µs/call |
| 29 | 62 | 236µs | 62 | 69µs | my $class = $metaclass->name; # spent 69µs making 62 calls to Class::MOP::Package::name, avg 1µs/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 | 62 | 344µs | 124 | 4.83ms | my $inherited_method # spent 4.78ms making 62 calls to Class::MOP::Class::find_next_method_by_name, avg 77µs/call
# spent 53µs making 62 calls to Class::MOP::Method::name, avg 860ns/call |
| 35 | = $metaclass->find_next_method_by_name( $self->name ); | ||||
| 36 | |||||
| 37 | 62 | 295µs | 60 | 134µs | if ( $inherited_method # spent 134µs making 60 calls to UNIVERSAL::isa, avg 2µs/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 | 62 | 365µs | 62 | 64µs | my $expected_class = $self->_expected_method_class # spent 64µs making 62 calls to Class::MOP::Method::Inlined::_expected_method_class, avg 1µs/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 | 16 | 143µs | 32 | 36µs | my $expected_method = $expected_class->can( $self->name ); # spent 26µs making 16 calls to UNIVERSAL::can, avg 2µs/call
# spent 10µs making 16 calls to Class::MOP::Method::name, avg 656ns/call |
| 53 | |||||
| 54 | 16 | 4µs | 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 | 16 | 222µs | 32 | 54µs | my $actual_method = $class->can( $self->name ) # spent 45µs making 16 calls to UNIVERSAL::can, avg 3µs/call
# spent 10µs making 16 calls to Class::MOP::Method::name, avg 600ns/call |
| 65 | or return 1; | ||||
| 66 | |||||
| 67 | # the method is what we wanted (probably Moose::Object::new) | ||||
| 68 | 16 | 152µs | 32 | 26µs | return 1 # spent 26µs making 32 calls to Scalar::Util::refaddr, avg 825ns/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 | 5µs | 1; | ||
| 107 | |||||
| 108 | # ABSTRACT: Method base class for methods which have been inlined | ||||
| 109 | |||||
| 110 | __END__ |