Filename | /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm |
Statements | Executed 1064313 statements in 3.91s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
266073 | 2 | 2 | 3.59s | 3.59s | gensym | Symbol::
1 | 1 | 1 | 6µs | 7µs | BEGIN@3 | Symbol::
1 | 1 | 1 | 5µs | 8µs | BEGIN@78 | Symbol::
1 | 1 | 1 | 5µs | 8µs | BEGIN@59 | Symbol::
1 | 1 | 1 | 4µs | 21µs | BEGIN@4 | Symbol::
1 | 1 | 1 | 4µs | 8µs | BEGIN@25 | Symbol::
1 | 1 | 1 | 4µs | 6µs | BEGIN@88 | Symbol::
0 | 0 | 0 | 0s | 0s | delete_package | Symbol::
0 | 0 | 0 | 0s | 0s | geniosym | Symbol::
0 | 0 | 0 | 0s | 0s | qualify | Symbol::
0 | 0 | 0 | 0s | 0s | qualify_to_ref | Symbol::
0 | 0 | 0 | 0s | 0s | ungensym | Symbol::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Symbol; | ||||
2 | |||||
3 | 2 | 14µs | 2 | 8µs | # spent 7µs (6+900ns) within Symbol::BEGIN@3 which was called:
# once (6µs+900ns) by IO::Handle::BEGIN@266 at line 3 # spent 7µs making 1 call to Symbol::BEGIN@3
# spent 900ns making 1 call to strict::import |
4 | 2 | 72µs | 2 | 38µs | # spent 21µs (4+17) within Symbol::BEGIN@4 which was called:
# once (4µs+17µs) by IO::Handle::BEGIN@266 at line 4 # spent 21µs making 1 call to Symbol::BEGIN@4
# spent 17µs making 1 call to warnings::import |
5 | |||||
6 | 1 | 500ns | require Exporter; | ||
7 | 1 | 7µs | our @ISA = qw(Exporter); | ||
8 | 1 | 400ns | our @EXPORT = qw(gensym ungensym qualify qualify_to_ref); | ||
9 | 1 | 200ns | our @EXPORT_OK = qw(delete_package geniosym); | ||
10 | |||||
11 | 1 | 100ns | our $VERSION = '1.09'; | ||
12 | |||||
13 | 1 | 200ns | my $genpkg = "Symbol::"; | ||
14 | 1 | 0s | my $genseq = 0; | ||
15 | |||||
16 | 1 | 4µs | my %global = map {$_ => 1} qw(ARGV ARGVOUT ENV INC SIG STDERR STDIN STDOUT); | ||
17 | |||||
18 | # | ||||
19 | # Note that we never _copy_ the glob; we just make a ref to it. | ||||
20 | # If we did copy it, then SVf_FAKE would be set on the copy, and | ||||
21 | # glob-specific behaviors (e.g. C<*$ref = \&func>) wouldn't work. | ||||
22 | # | ||||
23 | # spent 3.59s within Symbol::gensym which was called 266073 times, avg 13µs/call:
# 266070 times (3.59s+0s) by IO::Handle::new at line 325 of IO/Handle.pm, avg 13µs/call
# 3 times (8µs+0s) by main::BEGIN@30 at line 1876 of IPC/Cmd.pm, avg 3µs/call | ||||
24 | 266073 | 743ms | my $name = "GEN" . $genseq++; | ||
25 | 2 | 185µs | 2 | 13µs | # spent 8µs (4+4) within Symbol::BEGIN@25 which was called:
# once (4µs+4µs) by IO::Handle::BEGIN@266 at line 25 # spent 8µs making 1 call to Symbol::BEGIN@25
# spent 4µs making 1 call to strict::unimport |
26 | 266073 | 2.26s | my $ref = \*{$genpkg . $name}; | ||
27 | 266073 | 149ms | delete $$genpkg{$name}; | ||
28 | 266073 | 761ms | $ref; | ||
29 | } | ||||
30 | |||||
31 | sub geniosym () { | ||||
32 | my $sym = gensym(); | ||||
33 | # force the IO slot to be filled | ||||
34 | select(select $sym); | ||||
35 | *$sym{IO}; | ||||
36 | } | ||||
37 | |||||
38 | sub ungensym ($) {} | ||||
39 | |||||
40 | sub qualify ($;$) { | ||||
41 | my ($name) = @_; | ||||
42 | if (!ref($name) && index($name, '::') == -1 && index($name, "'") == -1) { | ||||
43 | my $pkg; | ||||
44 | # Global names: special character, "^xyz", or other. | ||||
45 | if ($name =~ /^(([^a-z])|(\^[a-z_]+))\z/i || $global{$name}) { | ||||
46 | # RGS 2001-11-05 : translate leading ^X to control-char | ||||
47 | $name =~ s/^\^([a-z_])/'qq(\c'.$1.')'/eei; | ||||
48 | $pkg = "main"; | ||||
49 | } | ||||
50 | else { | ||||
51 | $pkg = (@_ > 1) ? $_[1] : caller; | ||||
52 | } | ||||
53 | $name = $pkg . "::" . $name; | ||||
54 | } | ||||
55 | $name; | ||||
56 | } | ||||
57 | |||||
58 | sub qualify_to_ref ($;$) { | ||||
59 | 2 | 138µs | 2 | 12µs | # spent 8µs (5+4) within Symbol::BEGIN@59 which was called:
# once (5µs+4µs) by IO::Handle::BEGIN@266 at line 59 # spent 8µs making 1 call to Symbol::BEGIN@59
# spent 4µs making 1 call to strict::unimport |
60 | return \*{ qualify $_[0], @_ > 1 ? $_[1] : caller }; | ||||
61 | } | ||||
62 | |||||
63 | # | ||||
64 | # of Safe.pm lineage | ||||
65 | # | ||||
66 | sub delete_package ($) { | ||||
67 | my $pkg = shift; | ||||
68 | |||||
69 | # expand to full symbol table name if needed | ||||
70 | |||||
71 | unless ($pkg =~ /^main::.*::$/) { | ||||
72 | $pkg = "main$pkg" if $pkg =~ /^::/; | ||||
73 | $pkg = "main::$pkg" unless $pkg =~ /^main::/; | ||||
74 | $pkg .= '::' unless $pkg =~ /::$/; | ||||
75 | } | ||||
76 | |||||
77 | my($stem, $leaf) = $pkg =~ m/(.*::)(\w+::)$/; | ||||
78 | 2 | 45µs | 2 | 11µs | # spent 8µs (5+3) within Symbol::BEGIN@78 which was called:
# once (5µs+3µs) by IO::Handle::BEGIN@266 at line 78 # spent 8µs making 1 call to Symbol::BEGIN@78
# spent 3µs making 1 call to strict::unimport |
79 | my $stem_symtab = *{$stem}{HASH}; | ||||
80 | return unless defined $stem_symtab and exists $stem_symtab->{$leaf}; | ||||
81 | |||||
82 | # free all the symbols in the package | ||||
83 | |||||
84 | my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; | ||||
85 | foreach my $name (keys %$leaf_symtab) { | ||||
86 | undef *{$pkg . $name}; | ||||
87 | } | ||||
88 | 2 | 52µs | 2 | 8µs | # spent 6µs (4+2) within Symbol::BEGIN@88 which was called:
# once (4µs+2µs) by IO::Handle::BEGIN@266 at line 88 # spent 6µs making 1 call to Symbol::BEGIN@88
# spent 2µs making 1 call to strict::import |
89 | |||||
90 | # delete the symbol table | ||||
91 | |||||
92 | %$leaf_symtab = (); | ||||
93 | delete $stem_symtab->{$leaf}; | ||||
94 | } | ||||
95 | |||||
96 | 1 | 5µs | 1; |