Profile of utf8_heavy.pl

← Index
NYTProf Performance Profile «block view•line view•sub view»
For bin/dpath
Run on Tue Jun 5 15:31:33 2012
Reported on Tue Jun 5 15:31:44 2012

Filename | /home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/utf8_heavy.pl
Statements | Executed 8486 statements in 126ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 105ms | 124ms | utf8::::SWASHNEWutf8::SWASHNEW
4204 | 8 | 1 | 18.1ms | 18.1ms | utf8::::CORE:matchutf8::CORE:match (opcode)
1 | 1 | 1 | 830µs | 830µs | utf8::::CORE:sortutf8::CORE:sort (opcode)
22 | 1 | 1 | 80µs | 80µs | utf8::::is_utf8utf8::is_utf8 (xsub)
1 | 1 | 1 | 43µs | 113µs | utf8::::BEGIN@399utf8::BEGIN@399
1 | 1 | 1 | 41µs | 99µs | utf8::::BEGIN@117utf8::BEGIN@117
1 | 1 | 1 | 39µs | 56µs | utf8::::BEGIN@2utf8::BEGIN@2
1 | 1 | 1 | 39µs | 98µs | utf8::::BEGIN@460utf8::BEGIN@460
1 | 1 | 1 | 34µs | 64µs | utf8::::BEGIN@3utf8::BEGIN@3
5 | 5 | 1 | 33µs | 33µs | utf8::::CORE:substutf8::CORE:subst (opcode)
1 | 1 | 1 | 29µs | 77µs | utf8::::BEGIN@123utf8::BEGIN@123
1 | 1 | 1 | 18µs | 18µs | utf8::::BEGIN@135utf8::BEGIN@135
1 | 1 | 1 | 17µs | 17µs | utf8::::BEGIN@147utf8::BEGIN@147
1 | 1 | 1 | 8µs | 8µs | utf8::::upgradeutf8::upgrade (xsub)
0 | 0 | 0 | 0s | 0s | utf8::::DESTROYutf8::DESTROY
0 | 0 | 0 | 0s | 0s | utf8::::croakutf8::croak

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package utf8;
2 | 2 | 92µs | 2 | 74µs | # spent 56µs (39+17) within utf8::BEGIN@2 which was called: # once (39µs+17µs) by utf8::AUTOLOAD at line 2 use strict; # spent 56µs making 1 call to utf8::BEGIN@2 # spent 17µs making 1 call to strict::import
3 | 2 | 1.59ms | 2 | 95µs | # spent 64µs (34+30) within utf8::BEGIN@3 which was called: # once (34µs+30µs) by utf8::AUTOLOAD at line 3 use warnings; # spent 64µs making 1 call to utf8::BEGIN@3 # spent 30µs making 1 call to warnings::import
4 |  |  |  |  |
5 |  |  |  |  | sub DEBUG () { 0 }
6 |  |  |  |  |
7 |  |  |  |  | sub DESTROY {}
8 |  |  |  |  |
9 | 1 | 1µs |  |  | my %Cache;
10 |  |  |  |  |
11 |  |  |  |  | sub croak { require Carp; Carp::croak(@_) }
12 |  |  |  |  |
13 |  |  |  |  | ##
14 |  |  |  |  | ## "SWASH" == "SWATCH HASH". A "swatch" is a swatch of the Unicode landscape.
15 |  |  |  |  | ## It's a data structure that encodes a set of Unicode characters.
16 |  |  |  |  | ##
17 |  |  |  |  |
18 |  |  |  |  | {
19 |  |  |  |  | # If a floating point number is within this distance from the value of a
20 |  |  |  |  | # fraction, it is considered to be that fraction, even if many more digits
21 |  |  |  |  | # are specified that don't exactly match.
22 | 3 | 7µs |  |  | my $min_floating_slop;
23 |  |  |  |  |
24 |  |  |  |  | # To guard against this program calling something that in turn ends up
25 |  |  |  |  | # calling this program with the same inputs, and hence infinitely
26 |  |  |  |  | # recursing, we keep a stack of the properties that are currently in
27 |  |  |  |  | # progress, pushed upon entry, popped upon return.
28 |  |  |  |  | my @recursed;
29 |  |  |  |  |
30 |  |  |  |  | # spent 124ms (105+19.0) within utf8::SWASHNEW which was called: # once (105ms+19.0ms) by Safe::CORE:regcomp at line 18 of utf8.pm sub SWASHNEW {
31 | 18 | 1.29ms |  |  | my ($class, $type, $list, $minbits, $none) = @_;
32 |  |  |  |  | local $^D = 0 if $^D;
33 |  |  |  |  |
34 |  |  |  |  | $class = "" unless defined $class;
35 |  |  |  |  | print STDERR __LINE__, ": class=$class, type=$type, list=",
36 |  |  |  |  | (defined $list) ? $list : ':undef:',
37 |  |  |  |  | ", minbits=$minbits, none=$none\n" if DEBUG;
38 |  |  |  |  |
39 |  |  |  |  | ##
40 |  |  |  |  | ## Get the list of codepoints for the type.
41 |  |  |  |  | ## Called from swash_init (see utf8.c) or SWASHNEW itself.
42 |  |  |  |  | ##
43 |  |  |  |  | ## Callers of swash_init:
44 |  |  |  |  | ## op.c:pmtrans -- for tr/// and y///
45 |  |  |  |  | ## regexec.c:regclass_swash -- for /[]/, \p, and \P
46 |  |  |  |  | ## utf8.c:is_utf8_common -- for common Unicode properties
47 |  |  |  |  | ## utf8.c:to_utf8_case -- for lc, uc, ucfirst, etc. and //i
48 |  |  |  |  | ##
49 |  |  |  |  | ## Given a $type, our goal is to fill $list with the set of codepoint
50 |  |  |  |  | ## ranges. If $type is false, $list passed is used.
51 |  |  |  |  | ##
52 |  |  |  |  | ## $minbits:
53 |  |  |  |  | ## For binary properties, $minbits must be 1.
54 |  |  |  |  | ## For character mappings (case and transliteration), $minbits must
55 |  |  |  |  | ## be a number except 1.
56 |  |  |  |  | ##
57 |  |  |  |  | ## $list (or that filled according to $type):
58 |  |  |  |  | ## Refer to perlunicode.pod, "User-Defined Character Properties."
59 |  |  |  |  | ##
60 |  |  |  |  | ## For binary properties, only characters with the property value
61 |  |  |  |  | ## of True should be listed. The 3rd column, if any, will be ignored
62 |  |  |  |  | ##
63 |  |  |  |  | ## $none is undocumented, so I'm (khw) trying to do some documentation
64 |  |  |  |  | ## of it now. It appears to be if there is a mapping in an input file
65 |  |  |  |  | ## that maps to 'XXXX', then that is replaced by $none+1, expressed in
66 |  |  |  |  | ## hexadecimal. The only place I found it possibly used was in
67 |  |  |  |  | ## S_pmtrans in op.c.
68 |  |  |  |  | ##
69 |  |  |  |  | ## To make the parsing of $type clear, this code takes the a rather
70 |  |  |  |  | ## unorthodox approach of last'ing out of the block once we have the
71 |  |  |  |  | ## info we need. Were this to be a subroutine, the 'last' would just
72 |  |  |  |  | ## be a 'return'.
73 |  |  |  |  | ##
74 |  |  |  |  | my $file; ## file to load data from, and also part of the %Cache key.
75 |  |  |  |  | my $ListSorted = 0;
76 |  |  |  |  |
77 |  |  |  |  | # Change this to get a different set of Unicode tables
78 |  |  |  |  | my $unicore_dir = 'unicore';
79 |  |  |  |  |
80 | 9 | 75µs |  |  | if ($type)
81 |  |  |  |  | {
82 |  |  |  |  |
83 |  |  |  |  | # Verify that this isn't a recursive call for this property.
84 |  |  |  |  | # Can't use croak, as it may try to recurse here itself.
85 |  |  |  |  | my $class_type = $class . "::$type";
86 |  |  |  |  | if (grep { $_ eq $class_type } @recursed) {
87 |  |  |  |  | CORE::die "panic: Infinite recursion in SWASHNEW for '$type'\n";
88 |  |  |  |  | }
89 |  |  |  |  | push @recursed, $class_type;
90 |  |  |  |  |
91 |  |  | 1 | 13µs | $type =~ s/^\s+//; # spent 13µs making 1 call to utf8::CORE:subst
92 |  |  | 1 | 7µs | $type =~ s/\s+$//; # spent 7µs making 1 call to utf8::CORE:subst
93 |  |  |  |  |
94 |  |  |  |  | # regcomp.c surrounds the property name with '__" and '_i' if this
95 |  |  |  |  | # is to be caseless matching.
96 |  |  | 1 | 2µs | my $caseless = $type =~ s/^__(.*)_i$/$1/; # spent 2µs making 1 call to utf8::CORE:subst
97 |  |  |  |  |
98 |  |  |  |  | print STDERR __LINE__, ": type=$type, caseless=$caseless\n" if DEBUG;
99 |  |  |  |  |
100 | 15 | 1.54ms | 1 | 3µs | GETFILE: # spent 3µs making 1 call to utf8::CORE:subst
101 |  |  |  |  | {
102 |  |  |  |  | ##
103 |  |  |  |  | ## It could be a user-defined property. Look in current
104 |  |  |  |  | ## package if no package given
105 |  |  |  |  | ##
106 |  |  |  |  |
107 |  |  |  |  | my $caller1 = $type =~ s/(.+)::// ? $1 : caller(1);
108 |  |  |  |  |
109 |  |  | 1 | 4µs | if (defined $caller1 && $type =~ /^I[ns]\w+$/) { # spent 4µs making 1 call to utf8::CORE:match
110 |  |  |  |  | my $prop = "${caller1}::$type";
111 |  |  |  |  | if (exists &{$prop}) {
112 |  |  |  |  | # stolen from Scalar::Util::PP::tainted()
113 |  |  |  |  | my $tainted;
114 |  |  |  |  | {
115 |  |  |  |  | local($@, $SIG{__DIE__}, $SIG{__WARN__});
116 |  |  |  |  | local $^W = 0;
117 | 2 | 259µs | 2 | 157µs | # spent 99µs (41+58) within utf8::BEGIN@117 which was called: # once (41µs+58µs) by utf8::AUTOLOAD at line 117 no warnings; # spent 99µs making 1 call to utf8::BEGIN@117 # spent 58µs making 1 call to warnings::unimport
118 |  |  |  |  | eval { kill 0 * $prop };
119 |  |  |  |  | $tainted = 1 if $@ =~ /^Insecure/;
120 |  |  |  |  | }
121 |  |  |  |  | die "Insecure user-defined property \\p{$prop}\n"
122 |  |  |  |  | if $tainted;
123 | 2 | 248µs | 2 | 125µs | # spent 77µs (29+48) within utf8::BEGIN@123 which was called: # once (29µs+48µs) by utf8::AUTOLOAD at line 123 no strict 'refs'; # spent 77µs making 1 call to utf8::BEGIN@123 # spent 48µs making 1 call to strict::unimport
124 |  |  |  |  | $list = &{$prop}($caseless);
125 |  |  |  |  | last GETFILE;
126 |  |  |  |  | }
127 |  |  |  |  | }
128 |  |  |  |  |
129 |  |  |  |  | # During Perl's compilation, this routine may be called before
130 |  |  |  |  | # the tables are constructed. If so, we have a chicken/egg
131 |  |  |  |  | # problem. If we die, the tables never get constructed, so
132 |  |  |  |  | # keep going, but return an empty table so only what the code
133 |  |  |  |  | # has compiled in internally (currently ASCII/Latin1 range
134 |  |  |  |  | # matching) will work.
135 |  |  |  |  | # spent 18µs within utf8::BEGIN@135 which was called: # once (18µs+0s) by utf8::AUTOLOAD at line 139 BEGIN {
136 |  |  |  |  | # Poor man's constant, to avoid a run-time check.
137 | 1 | 31µs |  |  | $utf8::{miniperl}
138 |  |  |  |  | = \! defined &DynaLoader::boot_DynaLoader;
139 | 1 | 360µs | 1 | 18µs | } # spent 18µs making 1 call to utf8::BEGIN@135
140 | 1 | 31.2ms |  |  | if (miniperl) {
141 |  |  |  |  | eval "require '$unicore_dir/Heavy.pl'";
142 |  |  |  |  | last GETFILE if $@;
143 |  |  |  |  | }
144 |  |  |  |  | else {
145 |  |  |  |  | require "$unicore_dir/Heavy.pl";
146 |  |  |  |  | }
147 | 1 | 4.58ms | 1 | 17µs | # spent 17µs within utf8::BEGIN@147 which was called: # once (17µs+0s) by utf8::AUTOLOAD at line 147 BEGIN { delete $utf8::{miniperl} } # spent 17µs making 1 call to utf8::BEGIN@147
148 |  |  |  |  |
149 |  |  |  |  | # All property names are matched caselessly
150 |  |  |  |  | my $property_and_table = CORE::lc $type;
151 |  |  |  |  | print STDERR __LINE__, ": $property_and_table\n" if DEBUG;
152 |  |  |  |  |
153 |  |  |  |  | # See if is of the compound form 'property=value', where the
154 |  |  |  |  | # value indicates the table we should use.
155 |  |  |  |  | my ($property, $table, @remainder) =
156 |  |  |  |  | split /\s*[:=]\s*/, $property_and_table, -1;
157 |  |  |  |  | if (@remainder) {
158 |  |  |  |  | pop @recursed if @recursed;
159 |  |  |  |  | return $type;
160 |  |  |  |  | }
161 |  |  |  |  |
162 |  |  |  |  | my $prefix;
163 | 2 | 6µs |  |  | if (! defined $table) {
164 |  |  |  |  |
165 |  |  |  |  | # Here, is the single form. The property becomes empty, and
166 |  |  |  |  | # the whole value is the table.
167 |  |  |  |  | $table = $property;
168 |  |  |  |  | $prefix = $property = "";
169 |  |  |  |  | } else {
170 |  |  |  |  | print STDERR __LINE__, ": $property\n" if DEBUG;
171 |  |  |  |  |
172 |  |  |  |  | # Here it is the compound property=table form. The property
173 |  |  |  |  | # name is always loosely matched, which means remove any of
174 |  |  |  |  | # these:
175 |  |  |  |  | $property =~ s/[_\s-]//g;
176 |  |  |  |  |
177 |  |  |  |  | # And convert to canonical form. Quit if not valid.
178 |  |  |  |  | $property = $utf8::loose_property_name_of{$property};
179 |  |  |  |  | if (! defined $property) {
180 |  |  |  |  | pop @recursed if @recursed;
181 |  |  |  |  | return $type;
182 |  |  |  |  | }
183 |  |  |  |  |
184 |  |  |  |  | $prefix = "$property=";
185 |  |  |  |  |
186 |  |  |  |  | # If the rhs looks like it is a number...
187 |  |  |  |  | print STDERR __LINE__, ": table=$table\n" if DEBUG;
188 |  |  |  |  | if ($table =~ qr{ ^ [ \s 0-9 _ + / . -]+ $ }x) {
189 |  |  |  |  | print STDERR __LINE__, ": table=$table\n" if DEBUG;
190 |  |  |  |  |
191 |  |  |  |  | # Don't allow leading nor trailing slashes
192 |  |  |  |  | if ($table =~ / ^ \/ | \/ $ /x) {
193 |  |  |  |  | pop @recursed if @recursed;
194 |  |  |  |  | return $type;
195 |  |  |  |  | }
196 |  |  |  |  |
197 |  |  |  |  | # Split on slash, in case it is a rational, like \p{1/5}
198 |  |  |  |  | my @parts = split qr{ \s* / \s* }x, $table, -1;
199 |  |  |  |  | print __LINE__, ": $type\n" if @parts > 2 && DEBUG;
200 |  |  |  |  |
201 |  |  |  |  | # Can have maximum of one slash
202 |  |  |  |  | if (@parts > 2) {
203 |  |  |  |  | pop @recursed if @recursed;
204 |  |  |  |  | return $type;
205 |  |  |  |  | }
206 |  |  |  |  |
207 |  |  |  |  | foreach my $part (@parts) {
208 |  |  |  |  | print __LINE__, ": part=$part\n" if DEBUG;
209 |  |  |  |  |
210 |  |  |  |  | $part =~ s/^\+\s*//; # Remove leading plus
211 |  |  |  |  | $part =~ s/^-\s*/-/; # Remove blanks after unary
212 |  |  |  |  | # minus
213 |  |  |  |  |
214 |  |  |  |  | # Remove underscores between digits.
215 |  |  |  |  | $part =~ s/( ?<= [0-9] ) _ (?= [0-9] ) //xg;
216 |  |  |  |  |
217 |  |  |  |  | # No leading zeros (but don't make a single '0'
218 |  |  |  |  | # into a null string)
219 |  |  |  |  | $part =~ s/ ^ ( -? ) 0+ /$1/x;
220 |  |  |  |  | $part .= '0' if $part eq '-' || $part eq "";
221 |  |  |  |  |
222 |  |  |  |  | # No trailing zeros after a decimal point
223 |  |  |  |  | $part =~ s/ ( \. .*? ) 0+ $ /$1/x;
224 |  |  |  |  |
225 |  |  |  |  | # Begin with a 0 if a leading decimal point
226 |  |  |  |  | $part =~ s/ ^ ( -? ) \. /${1}0./x;
227 |  |  |  |  |
228 |  |  |  |  | # Ensure not a trailing decimal point: turn into an
229 |  |  |  |  | # integer
230 |  |  |  |  | $part =~ s/ \. $ //x;
231 |  |  |  |  |
232 |  |  |  |  | print STDERR __LINE__, ": part=$part\n" if DEBUG;
233 |  |  |  |  | #return $type if $part eq "";
234 |  |  |  |  |
235 |  |  |  |  | # Result better look like a number. (This test is
236 |  |  |  |  | # needed because, for example could have a plus in
237 |  |  |  |  | # the middle.)
238 |  |  |  |  | if ($part !~ / ^ -? [0-9]+ ( \. [0-9]+)? $ /x) {
239 |  |  |  |  | pop @recursed if @recursed;
240 |  |  |  |  | return $type;
241 |  |  |  |  | }
242 |  |  |  |  | }
243 |  |  |  |  |
244 |  |  |  |  | # If a rational...
245 |  |  |  |  | if (@parts == 2) {
246 |  |  |  |  |
247 |  |  |  |  | # If denominator is negative, get rid of it, and ...
248 |  |  |  |  | if ($parts[1] =~ s/^-//) {
249 |  |  |  |  |
250 |  |  |  |  | # If numerator is also negative, convert the
251 |  |  |  |  | # whole thing to positive, or move the minus to
252 |  |  |  |  | # the numerator
253 |  |  |  |  | if ($parts[0] !~ s/^-//) {
254 |  |  |  |  | $parts[0] = '-' . $parts[0];
255 |  |  |  |  | }
256 |  |  |  |  | }
257 |  |  |  |  | $table = join '/', @parts;
258 |  |  |  |  | }
259 |  |  |  |  | elsif ($property ne 'nv' || $parts[0] !~ /\./) {
260 |  |  |  |  |
261 |  |  |  |  | # Here is not numeric value, or doesn't have a
262 |  |  |  |  | # decimal point. No further manipulation is
263 |  |  |  |  | # necessary. (Note the hard-coded property name.
264 |  |  |  |  | # This could fail if other properties eventually
265 |  |  |  |  | # had fractions as well; perhaps the cjk ones
266 |  |  |  |  | # could evolve to do that. This hard-coding could
267 |  |  |  |  | # be fixed by mktables generating a list of
268 |  |  |  |  | # properties that could have fractions.)
269 |  |  |  |  | $table = $parts[0];
270 |  |  |  |  | } else {
271 |  |  |  |  |
272 |  |  |  |  | # Here is a floating point numeric_value. Try to
273 |  |  |  |  | # convert to rational. First see if is in the list
274 |  |  |  |  | # of known ones.
275 |  |  |  |  | if (exists $utf8::nv_floating_to_rational{$parts[0]}) {
276 |  |  |  |  | $table = $utf8::nv_floating_to_rational{$parts[0]};
277 |  |  |  |  | } else {
278 |  |  |  |  |
279 |  |  |  |  | # Here not in the list. See if is close
280 |  |  |  |  | # enough to something in the list. First
281 |  |  |  |  | # determine what 'close enough' means. It has
282 |  |  |  |  | # to be as tight as what mktables says is the
283 |  |  |  |  | # maximum slop, and as tight as how many
284 |  |  |  |  | # digits we were passed. That is, if the user
285 |  |  |  |  | # said .667, .6667, .66667, etc. we match as
286 |  |  |  |  | # many digits as they passed until get to
287 |  |  |  |  | # where it doesn't matter any more due to the
288 |  |  |  |  | # machine's precision. If they said .6666668,
289 |  |  |  |  | # we fail.
290 |  |  |  |  | (my $fraction = $parts[0]) =~ s/^.*\.//;
291 |  |  |  |  | my $epsilon = 10 ** - (length($fraction));
292 |  |  |  |  | if ($epsilon > $utf8::max_floating_slop) {
293 |  |  |  |  | $epsilon = $utf8::max_floating_slop;
294 |  |  |  |  | }
295 |  |  |  |  |
296 |  |  |  |  | # But it can't be tighter than the minimum
297 |  |  |  |  | # precision for this machine. If haven't
298 |  |  |  |  | # already calculated that minimum, do so now.
299 |  |  |  |  | if (! defined $min_floating_slop) {
300 |  |  |  |  |
301 |  |  |  |  | # Keep going down an order of magnitude
302 |  |  |  |  | # until find that adding this quantity to
303 |  |  |  |  | # 1 remains 1; but put an upper limit on
304 |  |  |  |  | # this so in case this algorithm doesn't
305 |  |  |  |  | # work properly on some platform, that we
306 |  |  |  |  | # won't loop forever.
307 |  |  |  |  | my $count = 0;
308 |  |  |  |  | $min_floating_slop = 1;
309 |  |  |  |  | while (1+ $min_floating_slop != 1
310 |  |  |  |  | && $count++ < 50)
311 |  |  |  |  | {
312 |  |  |  |  | my $next = $min_floating_slop / 10;
313 |  |  |  |  | last if $next == 0; # If underflows,
314 |  |  |  |  | # use previous one
315 |  |  |  |  | $min_floating_slop = $next;
316 |  |  |  |  | print STDERR __LINE__, ": min_float_slop=$min_floating_slop\n" if DEBUG;
317 |  |  |  |  | }
318 |  |  |  |  |
319 |  |  |  |  | # Back off a couple orders of magnitude,
320 |  |  |  |  | # just to be safe.
321 |  |  |  |  | $min_floating_slop *= 100;
322 |  |  |  |  | }
323 |  |  |  |  |
324 |  |  |  |  | if ($epsilon < $min_floating_slop) {
325 |  |  |  |  | $epsilon = $min_floating_slop;
326 |  |  |  |  | }
327 |  |  |  |  | print STDERR __LINE__, ": fraction=.$fraction; epsilon=$epsilon\n" if DEBUG;
328 |  |  |  |  |
329 |  |  |  |  | undef $table;
330 |  |  |  |  |
331 |  |  |  |  | # And for each possible rational in the table,
332 |  |  |  |  | # see if it is within epsilon of the input.
333 |  |  |  |  | foreach my $official
334 |  |  |  |  | (keys %utf8::nv_floating_to_rational)
335 |  |  |  |  | {
336 |  |  |  |  | print STDERR __LINE__, ": epsilon=$epsilon, official=$official, diff=", abs($parts[0] - $official), "\n" if DEBUG;
337 |  |  |  |  | if (abs($parts[0] - $official) < $epsilon) {
338 |  |  |  |  | $table =
339 |  |  |  |  | $utf8::nv_floating_to_rational{$official};
340 |  |  |  |  | last;
341 |  |  |  |  | }
342 |  |  |  |  | }
343 |  |  |  |  |
344 |  |  |  |  | # Quit if didn't find one.
345 |  |  |  |  | if (! defined $table) {
346 |  |  |  |  | pop @recursed if @recursed;
347 |  |  |  |  | return $type;
348 |  |  |  |  | }
349 |  |  |  |  | }
350 |  |  |  |  | }
351 |  |  |  |  | print STDERR __LINE__, ": $property=$table\n" if DEBUG;
352 |  |  |  |  | }
353 |  |  |  |  | }
354 |  |  |  |  |
355 |  |  |  |  | # Combine lhs (if any) and rhs to get something that matches
356 |  |  |  |  | # the syntax of the lookups.
357 |  |  |  |  | $property_and_table = "$prefix$table";
358 |  |  |  |  | print STDERR __LINE__, ": $property_and_table\n" if DEBUG;
359 |  |  |  |  |
360 |  |  |  |  | # First try stricter matching.
361 |  |  |  |  | $file = $utf8::stricter_to_file_of{$property_and_table};
362 |  |  |  |  |
363 |  |  |  |  | # If didn't find it, try again with looser matching by editing
364 |  |  |  |  | # out the applicable characters on the rhs and looking up
365 |  |  |  |  | # again.
366 | 3 | 63µs |  |  | if (! defined $file) {
367 |  |  | 1 | 8µs | $table =~ s/ [_\s-] //xg; # spent 8µs making 1 call to utf8::CORE:subst
368 |  |  |  |  | $property_and_table = "$prefix$table";
369 |  |  |  |  | print STDERR __LINE__, ": $property_and_table\n" if DEBUG;
370 |  |  |  |  | $file = $utf8::loose_to_file_of{$property_and_table};
371 |  |  |  |  | }
372 |  |  |  |  |
373 |  |  |  |  | # Add the constant and go fetch it in.
374 |  |  |  |  | if (defined $file) {
375 |  |  |  |  | if ($utf8::why_deprecated{$file}) {
376 |  |  |  |  | warnings::warnif('deprecated', "Use of '$type' in \\p{} or \\P{} is deprecated because: $utf8::why_deprecated{$file};");
377 |  |  |  |  | }
378 |  |  |  |  |
379 |  |  |  |  | if ($caseless
380 |  |  |  |  | && exists $utf8::caseless_equivalent{$property_and_table})
381 |  |  |  |  | {
382 |  |  |  |  | $file = $utf8::caseless_equivalent{$property_and_table};
383 |  |  |  |  | }
384 |  |  |  |  | $file= "$unicore_dir/lib/$file.pl";
385 |  |  |  |  | last GETFILE;
386 |  |  |  |  | }
387 |  |  |  |  | print STDERR __LINE__, ": didn't find $property_and_table\n" if DEBUG;
388 |  |  |  |  |
389 |  |  |  |  | ##
390 |  |  |  |  | ## See if it's a user-level "To".
391 |  |  |  |  | ##
392 |  |  |  |  |
393 |  |  |  |  | my $caller0 = caller(0);
394 |  |  |  |  |
395 | 2 | 12µs | 1 | 18µs | if (defined $caller0 && $type =~ /^To(?:\w+)$/) { # spent 18µs making 1 call to utf8::CORE:match
396 |  |  |  |  | my $map = $caller0 . "::" . $type;
397 |  |  |  |  |
398 |  |  |  |  | if (exists &{$map}) {
399 | 2 | 1.21ms | 2 | 184µs | # spent 113µs (43+70) within utf8::BEGIN@399 which was called: # once (43µs+70µs) by utf8::AUTOLOAD at line 399 no strict 'refs'; # spent 113µs making 1 call to utf8::BEGIN@399 # spent 70µs making 1 call to strict::unimport
400 |  |  |  |  |
401 |  |  |  |  | $list = &{$map};
402 |  |  |  |  | warnings::warnif('deprecated', "User-defined case-mapping '$type' is deprecated");
403 |  |  |  |  | last GETFILE;
404 |  |  |  |  | }
405 |  |  |  |  | }
406 |  |  |  |  |
407 |  |  |  |  | ##
408 |  |  |  |  | ## Last attempt -- see if it's a standard "To" name
409 |  |  |  |  | ## (e.g. "ToLower") ToTitle is used by ucfirst().
410 |  |  |  |  | ## The user-level way to access ToDigit() and ToFold()
411 |  |  |  |  | ## is to use Unicode::UCD.
412 |  |  |  |  | ##
413 | 2 | 25µs | 1 | 10µs | if ($type =~ /^To(Digit|Fold|Lower|Title|Upper)$/) { # spent 10µs making 1 call to utf8::CORE:match
414 |  |  |  |  | $file = "$unicore_dir/To/$1.pl";
415 |  |  |  |  | ## would like to test to see if $file actually exists....
416 |  |  |  |  | last GETFILE;
417 |  |  |  |  | }
418 |  |  |  |  |
419 |  |  |  |  | ##
420 |  |  |  |  | ## If we reach this line, it's because we couldn't figure
421 |  |  |  |  | ## out what to do with $type. Ouch.
422 |  |  |  |  | ##
423 |  |  |  |  |
424 |  |  |  |  | pop @recursed if @recursed;
425 |  |  |  |  | return $type;
426 |  |  |  |  | }
427 |  |  |  |  |
428 | 6 | 6.36ms |  |  | if (defined $file) {
429 |  |  |  |  | print STDERR __LINE__, ": found it (file='$file')\n" if DEBUG;
430 |  |  |  |  |
431 |  |  |  |  | ##
432 |  |  |  |  | ## If we reach here, it was due to a 'last GETFILE' above
433 |  |  |  |  | ## (exception: user-defined properties and mappings), so we
434 |  |  |  |  | ## have a filename, so now we load it if we haven't already.
435 |  |  |  |  | ## If we have, return the cached results. The cache key is the
436 |  |  |  |  | ## class and file to load.
437 |  |  |  |  | ##
438 |  |  |  |  | my $found = $Cache{$class, $file};
439 |  |  |  |  | if ($found and ref($found) eq $class) {
440 |  |  |  |  | print STDERR __LINE__, ": Returning cached '$file' for \\p{$type}\n" if DEBUG;
441 |  |  |  |  | pop @recursed if @recursed;
442 |  |  |  |  | return $found;
443 |  |  |  |  | }
444 |  |  |  |  |
445 |  |  |  |  | local $@;
446 |  |  |  |  | local $!;
447 |  |  |  |  | $list = do $file; die $@ if $@;
448 |  |  |  |  | }
449 |  |  |  |  |
450 |  |  |  |  | $ListSorted = 1; ## we know that these lists are sorted
451 |  |  |  |  | }
452 |  |  |  |  |
453 |  |  |  |  | my $extras;
454 |  |  |  |  | my $bits = $minbits;
455 |  |  |  |  |
456 | 5 | 13.6ms |  |  | if ($list) {
457 |  |  |  |  | my $taint = substr($list,0,0); # maintain taint
458 |  |  |  |  | my @tmp = split(/^/m, $list);
459 |  |  |  |  | my %seen;
460 | 2 | 3.02ms | 2 | 157µs | # spent 98µs (39+59) within utf8::BEGIN@460 which was called: # once (39µs+59µs) by utf8::AUTOLOAD at line 460 no warnings; # spent 98µs making 1 call to utf8::BEGIN@460 # spent 59µs making 1 call to warnings::unimport
461 |  |  | 1050 | 2.13ms | $extras = join '', $taint, grep /^[^0-9a-fA-F]/, @tmp; # spent 2.13ms making 1050 calls to utf8::CORE:match, avg 2µs/call
462 |  |  |  |  | $list = join '', $taint,
463 |  |  |  |  | map { $_->[1] }
464 |  |  | 1050 | 3.78ms | sort { $a->[0] <=> $b->[0] } # spent 3.78ms making 1050 calls to utf8::CORE:match, avg 4µs/call
465 |  |  | 1050 | 3.86ms | map { /^([0-9a-fA-F]+)/; [ CORE::hex($1), $_ ] } # spent 3.86ms making 1050 calls to utf8::CORE:match, avg 4µs/call
466 | 3150 | 34.1ms | 1 | 830µs | grep { /^([0-9a-fA-F]+)/ and not $seen{$1}++ } @tmp; # XXX doesn't do ranges right # spent 830µs making 1 call to utf8::CORE:sort
467 |  |  |  |  | }
468 |  |  |  |  |
469 |  |  |  |  | if ($none) {
470 |  |  |  |  | my $hextra = sprintf "%04x", $none + 1;
471 |  |  |  |  | $list =~ s/\tXXXX$/\t$hextra/mg;
472 |  |  |  |  | }
473 |  |  |  |  |
474 | 4 | 95µs |  |  | if ($minbits != 1 && $minbits < 32) { # not binary property
475 |  |  |  |  | my $top = 0;
476 |  |  | 1 | 44µs | while ($list =~ /^([0-9a-fA-F]+)(?:[\t]([0-9a-fA-F]+)?)(?:[ \t]([0-9a-fA-F]+))?/mg) { # spent 44µs making 1 call to utf8::CORE:match
477 | 5250 | 25.9ms |  |  | my $min = CORE::hex $1;
478 |  |  |  |  | my $max = defined $2 ? CORE::hex $2 : $min;
479 |  |  |  |  | my $val = defined $3 ? CORE::hex $3 : 0;
480 |  |  |  |  | $val += $max - $min if defined $3;
481 |  |  | 1050 | 8.27ms | $top = $val if $val > $top; # spent 8.27ms making 1050 calls to utf8::CORE:match, avg 8µs/call
482 |  |  |  |  | }
483 |  |  |  |  | my $topbits =
484 |  |  |  |  | $top > 0xffff ? 32 :
485 |  |  |  |  | $top > 0xff ? 16 : 8;
486 |  |  |  |  | $bits = $topbits if $bits < $topbits;
487 |  |  |  |  | }
488 |  |  |  |  |
489 |  |  |  |  | my @extras;
490 |  |  |  |  | if ($extras) {
491 |  |  |  |  | for my $x ($extras) {
492 |  |  |  |  | my $taint = substr($x,0,0); # maintain taint
493 |  |  |  |  | pos $x = 0;
494 |  |  |  |  | while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
495 |  |  |  |  | my $char = "$1$taint";
496 |  |  |  |  | my $name = "$2$taint";
497 |  |  |  |  | print STDERR __LINE__, ": char [$char] => name [$name]\n"
498 |  |  |  |  | if DEBUG;
499 |  |  |  |  | if ($char =~ /[-+!&]/) {
500 |  |  |  |  | my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
501 |  |  |  |  | my $subobj;
502 |  |  |  |  | if ($c eq 'utf8') {
503 |  |  |  |  | $subobj = utf8->SWASHNEW($t, "", $minbits, 0);
504 |  |  |  |  | }
505 |  |  |  |  | elsif (exists &$name) {
506 |  |  |  |  | $subobj = utf8->SWASHNEW($name, "", $minbits, 0);
507 |  |  |  |  | }
508 |  |  |  |  | elsif ($c =~ /^([0-9a-fA-F]+)/) {
509 |  |  |  |  | $subobj = utf8->SWASHNEW("", $c, $minbits, 0);
510 |  |  |  |  | }
511 |  |  |  |  | if (! ref $subobj) {
512 |  |  |  |  | pop @recursed if @recursed && $type;
513 |  |  |  |  | return $subobj;
514 |  |  |  |  | }
515 |  |  |  |  | push @extras, $name => $subobj;
516 |  |  |  |  | $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
517 |  |  |  |  | }
518 |  |  |  |  | }
519 |  |  |  |  | }
520 |  |  |  |  | }
521 |  |  |  |  |
522 |  |  |  |  | if (DEBUG) {
523 |  |  |  |  | print STDERR __LINE__, ": CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none";
524 |  |  |  |  | print STDERR "\nLIST =>\n$list" if defined $list;
525 |  |  |  |  | print STDERR "\nEXTRAS =>\n$extras" if defined $extras;
526 |  |  |  |  | print STDERR "\n";
527 |  |  |  |  | }
528 |  |  |  |  |
529 |  |  |  |  | my $SWASH = bless {
530 |  |  |  |  | TYPE => $type,
531 |  |  |  |  | BITS => $bits,
532 |  |  |  |  | EXTRAS => $extras,
533 |  |  |  |  | LIST => $list,
534 |  |  |  |  | NONE => $none,
535 |  |  |  |  | @extras,
536 |  |  |  |  | } => $class;
537 |  |  |  |  |
538 |  |  |  |  | if ($file) {
539 |  |  |  |  | $Cache{$class, $file} = $SWASH;
540 |  |  |  |  | }
541 |  |  |  |  |
542 |  |  |  |  | pop @recursed if @recursed && $type;
543 |  |  |  |  |
544 |  |  |  |  | return $SWASH;
545 |  |  |  |  | }
546 |  |  |  |  | }
547 |  |  |  |  |
548 |  |  |  |  | # Now SWASHGET is recasted into a C function S_swash_get (see utf8.c).
549 |  |  |  |  |
550 | 1 | 15µs |  |  | 1;
|  |  |  |  | # spent 18.1ms within utf8::CORE:match which was called 4204 times, avg 4µs/call: # 1050 times (8.27ms+0s) by utf8::SWASHNEW at line 481, avg 8µs/call # 1050 times (3.86ms+0s) by utf8::SWASHNEW at line 465, avg 4µs/call # 1050 times (3.78ms+0s) by utf8::SWASHNEW at line 464, avg 4µs/call # 1050 times (2.13ms+0s) by utf8::SWASHNEW at line 461, avg 2µs/call # once (44µs+0s) by utf8::SWASHNEW at line 476 # once (18µs+0s) by utf8::SWASHNEW at line 395 # once (10µs+0s) by utf8::SWASHNEW at line 413 # once (4µs+0s) by utf8::SWASHNEW at line 109 sub utf8::CORE:match; # opcode
|  |  |  |  | # spent 830µs within utf8::CORE:sort which was called: # once (830µs+0s) by utf8::SWASHNEW at line 466 sub utf8::CORE:sort; # opcode
|  |  |  |  | # spent 33µs within utf8::CORE:subst which was called 5 times, avg 7µs/call: # once (13µs+0s) by utf8::SWASHNEW at line 91 # once (8µs+0s) by utf8::SWASHNEW at line 367 # once (7µs+0s) by utf8::SWASHNEW at line 92 # once (3µs+0s) by utf8::SWASHNEW at line 100 # once (2µs+0s) by utf8::SWASHNEW at line 96 sub utf8::CORE:subst; # opcode
|  |  |  |  | # spent 80µs within utf8::is_utf8 which was called 22 times, avg 4µs/call: # 22 times (80µs+0s) by constant::import at line 123 of constant.pm, avg 4µs/call sub utf8::is_utf8; # xsub
|  |  |  |  | # spent 8µs within utf8::upgrade which was called: # once (8µs+0s) by Data::DPath::Context::BEGIN@23 at line 70 of Safe.pm sub utf8::upgrade; # xsub