| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Inlined.pm |
| Statements | Executed 958 statements in 23.0ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 111 | 2 | 1 | 15.4ms | 100ms | Class::MOP::Method::Inlined::can_be_inlined |
| 1 | 1 | 1 | 71µs | 88µs | Class::MOP::Method::Inlined::BEGIN@3 |
| 1 | 1 | 1 | 41µs | 291µs | Class::MOP::Method::Inlined::BEGIN@13 |
| 1 | 1 | 1 | 38µs | 106µs | Class::MOP::Method::Inlined::BEGIN@4 |
| 1 | 1 | 1 | 36µs | 260µs | Class::MOP::Method::Inlined::BEGIN@7 |
| 1 | 1 | 1 | 36µs | 186µs | Class::MOP::Method::Inlined::BEGIN@6 |
| 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 | |||||
| 3 | 3 | 98µs | 2 | 105µs | # spent 88µs (71+17) within Class::MOP::Method::Inlined::BEGIN@3 which was called:
# once (71µs+17µs) by base::import at line 3 # spent 88µs making 1 call to Class::MOP::Method::Inlined::BEGIN@3
# spent 17µs making 1 call to strict::import |
| 4 | 3 | 100µs | 2 | 173µs | # spent 106µs (38+67) within Class::MOP::Method::Inlined::BEGIN@4 which was called:
# once (38µs+67µs) by base::import at line 4 # spent 106µs making 1 call to Class::MOP::Method::Inlined::BEGIN@4
# spent 67µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 108µs | 2 | 337µs | # spent 186µs (36+151) within Class::MOP::Method::Inlined::BEGIN@6 which was called:
# once (36µs+151µs) by base::import at line 6 # spent 186µs making 1 call to Class::MOP::Method::Inlined::BEGIN@6
# spent 151µs making 1 call to Exporter::import |
| 7 | 3 | 205µs | 2 | 484µs | # spent 260µs (36+224) within Class::MOP::Method::Inlined::BEGIN@7 which was called:
# once (36µs+224µs) by base::import at line 7 # spent 260µs making 1 call to Class::MOP::Method::Inlined::BEGIN@7
# spent 224µs making 1 call to Exporter::import |
| 8 | |||||
| 9 | 1 | 4µs | our $VERSION = '1.11'; | ||
| 10 | 1 | 75µs | $VERSION = eval $VERSION; # spent 25µs executing statements in string eval | ||
| 11 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 12 | |||||
| 13 | 3 | 1.44ms | 2 | 291µs | # spent 291µs (41+250) within Class::MOP::Method::Inlined::BEGIN@13 which was called:
# once (41µs+250µs) by base::import at line 13 # spent 291µs making 1 call to Class::MOP::Method::Inlined::BEGIN@13
# spent 250µs making 1 call to base::import, recursion: max depth 2, sum of overlapping time 250µs |
| 14 | |||||
| 15 | 111 | 1.58ms | sub _expected_method_class { $_[0]{_expected_method_class} } | ||
| 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 100ms (15.4+85.0) within Class::MOP::Method::Inlined::can_be_inlined which was called 111 times, avg 904µs/call:
# 72 times (11.3ms+56.5ms) by Class::MOP::Class::_inline_constructor at line 1338 of Class/MOP/Class.pm, avg 943µs/call
# 39 times (4.04ms+28.5ms) by Class::MOP::Class::_inline_destructor at line 1371 of Class/MOP/Class.pm, avg 834µs/call | ||||
| 33 | 111 | 426µs | my $self = shift; | ||
| 34 | 111 | 1.29ms | 111 | 1.10ms | my $metaclass = $self->associated_metaclass; # spent 808µs making 80 calls to Class::MOP::Method::associated_metaclass, avg 10µs/call
# spent 290µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call |
| 35 | 111 | 2.57ms | 111 | 863µs | my $class = $metaclass->name; # spent 863µs making 111 calls to Class::MOP::Package::name, avg 8µs/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 | 111 | 3.36ms | 222 | 78.2ms | my $inherited_method # spent 77.6ms making 111 calls to Class::MOP::Class::find_next_method_by_name, avg 699µs/call
# spent 629µs making 111 calls to Class::MOP::Method::name, avg 6µs/call |
| 41 | = $metaclass->find_next_method_by_name( $self->name ); | ||||
| 42 | |||||
| 43 | 111 | 3.15ms | 106 | 1.54ms | if ( $inherited_method # spent 1.54ms making 106 calls to UNIVERSAL::isa, avg 15µ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 | 111 | 2.50ms | 111 | 1.40ms | my $expected_class = $self->_expected_method_class # spent 1.40ms making 111 calls to Class::MOP::Method::Inlined::_expected_method_class, avg 13µs/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 | 41 | 1.66ms | 82 | 656µs | my $expected_method = $expected_class->can( $self->name ); # spent 428µs making 41 calls to UNIVERSAL::can, avg 10µs/call
# spent 228µs making 41 calls to Class::MOP::Method::name, avg 6µs/call |
| 59 | |||||
| 60 | 41 | 102µs | 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 | 41 | 2.76ms | 82 | 863µs | my $actual_method = $class->can( $self->name ) # spent 658µs making 41 calls to UNIVERSAL::can, avg 16µs/call
# spent 205µs making 41 calls to Class::MOP::Method::name, avg 5µs/call |
| 71 | or return 1; | ||||
| 72 | |||||
| 73 | # the method is what we wanted (probably Moose::Object::new) | ||||
| 74 | 39 | 1.58ms | 78 | 397µs | return 1 # spent 397µs making 78 calls to Scalar::Util::refaddr, avg 5µs/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 | 11µs | 1; | ||
| 113 | |||||
| 114 | __END__ |