Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/utf8_heavy.pl |
Statements | Executed 543 statements in 11.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
9 | 6 | 4 | 10.8ms | 10.9ms | SWASHNEW | utf8::
1 | 1 | 1 | 967µs | 1.36ms | BEGIN@4 | utf8::
50 | 6 | 1 | 40µs | 40µs | CORE:subst (opcode) | utf8::
5 | 1 | 1 | 36µs | 41µs | _loose_name | utf8::
1 | 1 | 1 | 12µs | 26µs | BEGIN@149 | utf8::
1 | 1 | 1 | 11µs | 22µs | BEGIN@544 | utf8::
1 | 1 | 1 | 9µs | 20µs | BEGIN@2 | utf8::
1 | 1 | 1 | 8µs | 20µs | BEGIN@656 | utf8::
1 | 1 | 1 | 8µs | 20µs | BEGIN@155 | utf8::
1 | 1 | 1 | 7µs | 10µs | BEGIN@3 | utf8::
14 | 2 | 1 | 7µs | 7µs | CORE:match (opcode) | utf8::
1 | 1 | 1 | 4µs | 4µs | BEGIN@168 | utf8::
1 | 1 | 1 | 4µs | 4µs | BEGIN@180 | utf8::
0 | 0 | 0 | 0s | 0s | DESTROY | utf8::
0 | 0 | 0 | 0s | 0s | croak | utf8::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package utf8; | ||||
2 | 2 | 19µs | 2 | 32µs | # spent 20µs (9+12) within utf8::BEGIN@2 which was called:
# once (9µs+12µs) by utf8::AUTOLOAD at line 2 # spent 20µs making 1 call to utf8::BEGIN@2
# spent 12µs making 1 call to strict::import |
3 | 2 | 18µs | 2 | 14µs | # spent 10µs (7+4) within utf8::BEGIN@3 which was called:
# once (7µs+4µs) by utf8::AUTOLOAD at line 3 # spent 10µs making 1 call to utf8::BEGIN@3
# spent 4µs making 1 call to warnings::import |
4 | 2 | 542µs | 2 | 1.41ms | # spent 1.36ms (967µs+391µs) within utf8::BEGIN@4 which was called:
# once (967µs+391µs) by utf8::AUTOLOAD at line 4 # spent 1.36ms making 1 call to utf8::BEGIN@4
# spent 57µs making 1 call to re::import |
5 | # resulting in a recursive call | ||||
6 | |||||
7 | sub DEBUG () { 0 } | ||||
8 | $|=1 if DEBUG; | ||||
9 | |||||
10 | sub DESTROY {} | ||||
11 | |||||
12 | 1 | 200ns | my %Cache; | ||
13 | |||||
14 | sub croak { require Carp; Carp::croak(@_) } | ||||
15 | |||||
16 | # spent 41µs (36+5) within utf8::_loose_name which was called 5 times, avg 8µs/call:
# 5 times (36µs+5µs) by utf8::SWASHNEW at line 401, avg 8µs/call | ||||
17 | # Given a lowercase property or property-value name, return its | ||||
18 | # standardized version that is expected for look-up in the 'loose' hashes | ||||
19 | # in Heavy.pl (hence, this depends on what mktables does). This squeezes | ||||
20 | # out blanks, underscores and dashes. The complication stems from the | ||||
21 | # grandfathered-in 'L_', which retains a single trailing underscore. | ||||
22 | |||||
23 | 5 | 18µs | 5 | 2µs | my $loose = $_[0] =~ s/[-\s_]//rg; # spent 2µs making 5 calls to utf8::CORE:subst, avg 500ns/call |
24 | |||||
25 | 5 | 25µs | 5 | 3µs | return $loose if $loose !~ / ^ (?: is | to )? l $/x; # spent 3µs making 5 calls to utf8::CORE:match, avg 520ns/call |
26 | return 'l_' if $_[0] =~ / l .* _ /x; # If original had a trailing '_' | ||||
27 | return $loose; | ||||
28 | } | ||||
29 | |||||
30 | ## | ||||
31 | ## "SWASH" == "SWATCH HASH". A "swatch" is a swatch of the Unicode landscape. | ||||
32 | ## It's a data structure that encodes a set of Unicode characters. | ||||
33 | ## | ||||
34 | |||||
35 | { | ||||
36 | # If a floating point number is within this distance from the value of a | ||||
37 | # fraction, it is considered to be that fraction, even if many more digits | ||||
38 | # are specified that don't exactly match. | ||||
39 | 2 | 200ns | my $min_floating_slop; | ||
40 | |||||
41 | # To guard against this program calling something that in turn ends up | ||||
42 | # calling this program with the same inputs, and hence infinitely | ||||
43 | # recursing, we keep a stack of the properties that are currently in | ||||
44 | # progress, pushed upon entry, popped upon return. | ||||
45 | 1 | 500ns | my @recursed; | ||
46 | |||||
47 | # spent 10.9ms (10.8+82µs) within utf8::SWASHNEW which was called 9 times, avg 1.21ms/call:
# 2 times (523µs+10µs) by charnames::BEGIN@6 at line 175 of _charnames.pm, avg 266µs/call
# 2 times (441µs+8µs) by charnames::BEGIN@6 at line 230 of _charnames.pm, avg 224µs/call
# 2 times (272µs+21µs) by charnames::BEGIN@6 at line 202 of _charnames.pm, avg 147µs/call
# once (9.32ms+21µs) by Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@16 at line 18 of utf8.pm
# once (259µs+12µs) by Lingua::EN::Inflect::CORE:match at line 1051 of Lingua/EN/Inflect.pm
# once (29µs+10µs) by Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars::BEGIN@16 at line 231 of Email/Address.pm | ||||
48 | 9 | 7µs | my ($class, $type, $list, $minbits, $none) = @_; | ||
49 | 9 | 2µs | my $user_defined = 0; | ||
50 | 9 | 5µs | local $^D = 0 if $^D; | ||
51 | |||||
52 | 9 | 2µs | $class = "" unless defined $class; | ||
53 | print STDERR __LINE__, ": class=$class, type=$type, list=", | ||||
54 | (defined $list) ? $list : ':undef:', | ||||
55 | ", minbits=$minbits, none=$none\n" if DEBUG; | ||||
56 | |||||
57 | ## | ||||
58 | ## Get the list of codepoints for the type. | ||||
59 | ## Called from swash_init (see utf8.c) or SWASHNEW itself. | ||||
60 | ## | ||||
61 | ## Callers of swash_init: | ||||
62 | ## op.c:pmtrans -- for tr/// and y/// | ||||
63 | ## regexec.c:regclass_swash -- for /[]/, \p, and \P | ||||
64 | ## utf8.c:is_utf8_common -- for common Unicode properties | ||||
65 | ## utf8.c:to_utf8_case -- for lc, uc, ucfirst, etc. and //i | ||||
66 | ## Unicode::UCD::prop_invlist | ||||
67 | ## Unicode::UCD::prop_invmap | ||||
68 | ## | ||||
69 | ## Given a $type, our goal is to fill $list with the set of codepoint | ||||
70 | ## ranges. If $type is false, $list passed is used. | ||||
71 | ## | ||||
72 | ## $minbits: | ||||
73 | ## For binary properties, $minbits must be 1. | ||||
74 | ## For character mappings (case and transliteration), $minbits must | ||||
75 | ## be a number except 1. | ||||
76 | ## | ||||
77 | ## $list (or that filled according to $type): | ||||
78 | ## Refer to perlunicode.pod, "User-Defined Character Properties." | ||||
79 | ## | ||||
80 | ## For binary properties, only characters with the property value | ||||
81 | ## of True should be listed. The 3rd column, if any, will be ignored | ||||
82 | ## | ||||
83 | ## $none is undocumented, so I'm (khw) trying to do some documentation | ||||
84 | ## of it now. It appears to be if there is a mapping in an input file | ||||
85 | ## that maps to 'XXXX', then that is replaced by $none+1, expressed in | ||||
86 | ## hexadecimal. It is used somehow in tr///. | ||||
87 | ## | ||||
88 | ## To make the parsing of $type clear, this code takes the a rather | ||||
89 | ## unorthodox approach of last'ing out of the block once we have the | ||||
90 | ## info we need. Were this to be a subroutine, the 'last' would just | ||||
91 | ## be a 'return'. | ||||
92 | ## | ||||
93 | # If a problem is found $type is returned; | ||||
94 | # Upon success, a new (or cached) blessed object is returned with | ||||
95 | # keys TYPE, BITS, EXTRAS, LIST, and NONE with values having the | ||||
96 | # same meanings as the input parameters. | ||||
97 | # SPECIALS contains a reference to any special-treatment hash in the | ||||
98 | # INVERT_IT is non-zero if the result should be inverted before use | ||||
99 | # USER_DEFINED is non-zero if the result came from a user-defined | ||||
100 | # property. | ||||
101 | 9 | 600ns | my $file; ## file to load data from, and also part of the %Cache key. | ||
102 | |||||
103 | # Change this to get a different set of Unicode tables | ||||
104 | 9 | 2µs | my $unicore_dir = 'unicore'; | ||
105 | 9 | 1µs | my $invert_it = 0; | ||
106 | 9 | 800ns | my $list_is_from_mktables = 0; # Is $list returned from a mktables | ||
107 | # generated file? If so, we know it's | ||||
108 | # well behaved. | ||||
109 | |||||
110 | 9 | 1µs | if ($type) | ||
111 | { | ||||
112 | # Verify that this isn't a recursive call for this property. | ||||
113 | # Can't use croak, as it may try to recurse to here itself. | ||||
114 | 9 | 6µs | my $class_type = $class . "::$type"; | ||
115 | 9 | 4µs | if (grep { $_ eq $class_type } @recursed) { | ||
116 | CORE::die "panic: Infinite recursion in SWASHNEW for '$type'\n"; | ||||
117 | } | ||||
118 | 9 | 4µs | push @recursed, $class_type; | ||
119 | |||||
120 | 9 | 34µs | 9 | 12µs | $type =~ s/^\s+//; # spent 12µs making 9 calls to utf8::CORE:subst, avg 1µs/call |
121 | 9 | 27µs | 9 | 15µs | $type =~ s/\s+$//; # spent 15µs making 9 calls to utf8::CORE:subst, avg 2µs/call |
122 | |||||
123 | # regcomp.c surrounds the property name with '__" and '_i' if this | ||||
124 | # is to be caseless matching. | ||||
125 | 9 | 17µs | 9 | 3µs | my $caseless = $type =~ s/^(.*)__(.*)_i$/$1$2/; # spent 3µs making 9 calls to utf8::CORE:subst, avg 378ns/call |
126 | |||||
127 | print STDERR __LINE__, ": type=$type, caseless=$caseless\n" if DEBUG; | ||||
128 | |||||
129 | 9 | 6µs | GETFILE: | ||
130 | { | ||||
131 | ## | ||||
132 | ## It could be a user-defined property. Look in current | ||||
133 | ## package if no package given | ||||
134 | ## | ||||
135 | |||||
136 | |||||
137 | 9 | 1µs | my $caller0 = caller(0); | ||
138 | 9 | 20µs | 9 | 3µs | my $caller1 = $type =~ s/(.+)::// ? $1 : $caller0 eq 'main' ? # spent 3µs making 9 calls to utf8::CORE:subst, avg 322ns/call |
139 | 'main' : caller(1); | ||||
140 | |||||
141 | 9 | 22µs | 9 | 4µs | if (defined $caller1 && $type =~ /^I[ns]\w+$/) { # spent 4µs making 9 calls to utf8::CORE:match, avg 433ns/call |
142 | my $prop = "${caller1}::$type"; | ||||
143 | if (exists &{$prop}) { | ||||
144 | # stolen from Scalar::Util::PP::tainted() | ||||
145 | my $tainted; | ||||
146 | { | ||||
147 | local($@, $SIG{__DIE__}, $SIG{__WARN__}); | ||||
148 | local $^W = 0; | ||||
149 | 2 | 70µs | 2 | 41µs | # spent 26µs (12+14) within utf8::BEGIN@149 which was called:
# once (12µs+14µs) by utf8::AUTOLOAD at line 149 # spent 26µs making 1 call to utf8::BEGIN@149
# spent 14µs making 1 call to warnings::unimport |
150 | eval { kill 0 * $prop }; | ||||
151 | $tainted = 1 if $@ =~ /^Insecure/; | ||||
152 | } | ||||
153 | die "Insecure user-defined property \\p{$prop}\n" | ||||
154 | if $tainted; | ||||
155 | 2 | 56µs | 2 | 31µs | # spent 20µs (8+12) within utf8::BEGIN@155 which was called:
# once (8µs+12µs) by utf8::AUTOLOAD at line 155 # spent 20µs making 1 call to utf8::BEGIN@155
# spent 12µs making 1 call to strict::unimport |
156 | $list = &{$prop}($caseless); | ||||
157 | $user_defined = 1; | ||||
158 | last GETFILE; | ||||
159 | } | ||||
160 | } | ||||
161 | |||||
162 | # During Perl's compilation, this routine may be called before | ||||
163 | # the tables are constructed. If so, we have a chicken/egg | ||||
164 | # problem. If we die, the tables never get constructed, so | ||||
165 | # keep going, but return an empty table so only what the code | ||||
166 | # has compiled in internally (currently ASCII/Latin1 range | ||||
167 | # matching) will work. | ||||
168 | # spent 4µs within utf8::BEGIN@168 which was called:
# once (4µs+0s) by utf8::AUTOLOAD at line 172 | ||||
169 | # Poor man's constant, to avoid a run-time check. | ||||
170 | 1 | 5µs | $utf8::{miniperl} | ||
171 | = \! defined &DynaLoader::boot_DynaLoader; | ||||
172 | 1 | 61µs | 1 | 4µs | } # spent 4µs making 1 call to utf8::BEGIN@168 |
173 | 9 | 3µs | if (miniperl) { | ||
174 | eval "require '$unicore_dir/Heavy.pl'"; | ||||
175 | last GETFILE if $@; | ||||
176 | } | ||||
177 | else { | ||||
178 | 9 | 6.92ms | require "$unicore_dir/Heavy.pl"; | ||
179 | } | ||||
180 | 1 | 1.33ms | 1 | 4µs | # spent 4µs within utf8::BEGIN@180 which was called:
# once (4µs+0s) by utf8::AUTOLOAD at line 180 # spent 4µs making 1 call to utf8::BEGIN@180 |
181 | |||||
182 | # All property names are matched caselessly | ||||
183 | 9 | 6µs | my $property_and_table = CORE::lc $type; | ||
184 | print STDERR __LINE__, ": $property_and_table\n" if DEBUG; | ||||
185 | |||||
186 | # See if is of the compound form 'property=value', where the | ||||
187 | # value indicates the table we should use. | ||||
188 | 9 | 18µs | my ($property, $table, @remainder) = | ||
189 | split /\s*[:=]\s*/, $property_and_table, -1; | ||||
190 | 9 | 2µs | if (@remainder) { | ||
191 | pop @recursed if @recursed; | ||||
192 | return $type; | ||||
193 | } | ||||
194 | |||||
195 | 9 | 1µs | my $prefix; | ||
196 | 9 | 3µs | if (! defined $table) { | ||
197 | |||||
198 | # Here, is the single form. The property becomes empty, and | ||||
199 | # the whole value is the table. | ||||
200 | 9 | 1µs | $table = $property; | ||
201 | 9 | 2µs | $prefix = $property = ""; | ||
202 | } else { | ||||
203 | print STDERR __LINE__, ": $property\n" if DEBUG; | ||||
204 | |||||
205 | # Here it is the compound property=table form. The property | ||||
206 | # name is always loosely matched, and always can have an | ||||
207 | # optional 'is' prefix (which isn't true in the single | ||||
208 | # form). | ||||
209 | $property = _loose_name($property) =~ s/^is//r; | ||||
210 | |||||
211 | # And convert to canonical form. Quit if not valid. | ||||
212 | $property = $utf8::loose_property_name_of{$property}; | ||||
213 | if (! defined $property) { | ||||
214 | pop @recursed if @recursed; | ||||
215 | return $type; | ||||
216 | } | ||||
217 | |||||
218 | $prefix = "$property="; | ||||
219 | |||||
220 | # If the rhs looks like it is a number... | ||||
221 | print STDERR __LINE__, ": table=$table\n" if DEBUG; | ||||
222 | if ($table =~ qr{ ^ [ \s 0-9 _ + / . -]+ $ }x) { | ||||
223 | print STDERR __LINE__, ": table=$table\n" if DEBUG; | ||||
224 | |||||
225 | # Don't allow leading nor trailing slashes | ||||
226 | if ($table =~ / ^ \/ | \/ $ /x) { | ||||
227 | pop @recursed if @recursed; | ||||
228 | return $type; | ||||
229 | } | ||||
230 | |||||
231 | # Split on slash, in case it is a rational, like \p{1/5} | ||||
232 | my @parts = split qr{ \s* / \s* }x, $table, -1; | ||||
233 | print __LINE__, ": $type\n" if @parts > 2 && DEBUG; | ||||
234 | |||||
235 | # Can have maximum of one slash | ||||
236 | if (@parts > 2) { | ||||
237 | pop @recursed if @recursed; | ||||
238 | return $type; | ||||
239 | } | ||||
240 | |||||
241 | foreach my $part (@parts) { | ||||
242 | print __LINE__, ": part=$part\n" if DEBUG; | ||||
243 | |||||
244 | $part =~ s/^\+\s*//; # Remove leading plus | ||||
245 | $part =~ s/^-\s*/-/; # Remove blanks after unary | ||||
246 | # minus | ||||
247 | |||||
248 | # Remove underscores between digits. | ||||
249 | $part =~ s/(?<= [0-9] ) _ (?= [0-9] ) //xg; | ||||
250 | |||||
251 | # No leading zeros (but don't make a single '0' | ||||
252 | # into a null string) | ||||
253 | $part =~ s/ ^ ( -? ) 0+ /$1/x; | ||||
254 | $part .= '0' if $part eq '-' || $part eq ""; | ||||
255 | |||||
256 | # No trailing zeros after a decimal point | ||||
257 | $part =~ s/ ( \. .*? ) 0+ $ /$1/x; | ||||
258 | |||||
259 | # Begin with a 0 if a leading decimal point | ||||
260 | $part =~ s/ ^ ( -? ) \. /${1}0./x; | ||||
261 | |||||
262 | # Ensure not a trailing decimal point: turn into an | ||||
263 | # integer | ||||
264 | $part =~ s/ \. $ //x; | ||||
265 | |||||
266 | print STDERR __LINE__, ": part=$part\n" if DEBUG; | ||||
267 | #return $type if $part eq ""; | ||||
268 | |||||
269 | # Result better look like a number. (This test is | ||||
270 | # needed because, for example could have a plus in | ||||
271 | # the middle.) | ||||
272 | if ($part !~ / ^ -? [0-9]+ ( \. [0-9]+)? $ /x) { | ||||
273 | pop @recursed if @recursed; | ||||
274 | return $type; | ||||
275 | } | ||||
276 | } | ||||
277 | |||||
278 | # If a rational... | ||||
279 | if (@parts == 2) { | ||||
280 | |||||
281 | # If denominator is negative, get rid of it, and ... | ||||
282 | if ($parts[1] =~ s/^-//) { | ||||
283 | |||||
284 | # If numerator is also negative, convert the | ||||
285 | # whole thing to positive, or move the minus to | ||||
286 | # the numerator | ||||
287 | if ($parts[0] !~ s/^-//) { | ||||
288 | $parts[0] = '-' . $parts[0]; | ||||
289 | } | ||||
290 | } | ||||
291 | $table = join '/', @parts; | ||||
292 | } | ||||
293 | elsif ($property ne 'nv' || $parts[0] !~ /\./) { | ||||
294 | |||||
295 | # Here is not numeric value, or doesn't have a | ||||
296 | # decimal point. No further manipulation is | ||||
297 | # necessary. (Note the hard-coded property name. | ||||
298 | # This could fail if other properties eventually | ||||
299 | # had fractions as well; perhaps the cjk ones | ||||
300 | # could evolve to do that. This hard-coding could | ||||
301 | # be fixed by mktables generating a list of | ||||
302 | # properties that could have fractions.) | ||||
303 | $table = $parts[0]; | ||||
304 | } else { | ||||
305 | |||||
306 | # Here is a floating point numeric_value. Try to | ||||
307 | # convert to rational. First see if is in the list | ||||
308 | # of known ones. | ||||
309 | if (exists $utf8::nv_floating_to_rational{$parts[0]}) { | ||||
310 | $table = $utf8::nv_floating_to_rational{$parts[0]}; | ||||
311 | } else { | ||||
312 | |||||
313 | # Here not in the list. See if is close | ||||
314 | # enough to something in the list. First | ||||
315 | # determine what 'close enough' means. It has | ||||
316 | # to be as tight as what mktables says is the | ||||
317 | # maximum slop, and as tight as how many | ||||
318 | # digits we were passed. That is, if the user | ||||
319 | # said .667, .6667, .66667, etc. we match as | ||||
320 | # many digits as they passed until get to | ||||
321 | # where it doesn't matter any more due to the | ||||
322 | # machine's precision. If they said .6666668, | ||||
323 | # we fail. | ||||
324 | (my $fraction = $parts[0]) =~ s/^.*\.//; | ||||
325 | my $epsilon = 10 ** - (length($fraction)); | ||||
326 | if ($epsilon > $utf8::max_floating_slop) { | ||||
327 | $epsilon = $utf8::max_floating_slop; | ||||
328 | } | ||||
329 | |||||
330 | # But it can't be tighter than the minimum | ||||
331 | # precision for this machine. If haven't | ||||
332 | # already calculated that minimum, do so now. | ||||
333 | if (! defined $min_floating_slop) { | ||||
334 | |||||
335 | # Keep going down an order of magnitude | ||||
336 | # until find that adding this quantity to | ||||
337 | # 1 remains 1; but put an upper limit on | ||||
338 | # this so in case this algorithm doesn't | ||||
339 | # work properly on some platform, that we | ||||
340 | # won't loop forever. | ||||
341 | my $count = 0; | ||||
342 | $min_floating_slop = 1; | ||||
343 | while (1+ $min_floating_slop != 1 | ||||
344 | && $count++ < 50) | ||||
345 | { | ||||
346 | my $next = $min_floating_slop / 10; | ||||
347 | last if $next == 0; # If underflows, | ||||
348 | # use previous one | ||||
349 | $min_floating_slop = $next; | ||||
350 | print STDERR __LINE__, ": min_float_slop=$min_floating_slop\n" if DEBUG; | ||||
351 | } | ||||
352 | |||||
353 | # Back off a couple orders of magnitude, | ||||
354 | # just to be safe. | ||||
355 | $min_floating_slop *= 100; | ||||
356 | } | ||||
357 | |||||
358 | if ($epsilon < $min_floating_slop) { | ||||
359 | $epsilon = $min_floating_slop; | ||||
360 | } | ||||
361 | print STDERR __LINE__, ": fraction=.$fraction; epsilon=$epsilon\n" if DEBUG; | ||||
362 | |||||
363 | undef $table; | ||||
364 | |||||
365 | # And for each possible rational in the table, | ||||
366 | # see if it is within epsilon of the input. | ||||
367 | foreach my $official | ||||
368 | (keys %utf8::nv_floating_to_rational) | ||||
369 | { | ||||
370 | print STDERR __LINE__, ": epsilon=$epsilon, official=$official, diff=", abs($parts[0] - $official), "\n" if DEBUG; | ||||
371 | if (abs($parts[0] - $official) < $epsilon) { | ||||
372 | $table = | ||||
373 | $utf8::nv_floating_to_rational{$official}; | ||||
374 | last; | ||||
375 | } | ||||
376 | } | ||||
377 | |||||
378 | # Quit if didn't find one. | ||||
379 | if (! defined $table) { | ||||
380 | pop @recursed if @recursed; | ||||
381 | return $type; | ||||
382 | } | ||||
383 | } | ||||
384 | } | ||||
385 | print STDERR __LINE__, ": $property=$table\n" if DEBUG; | ||||
386 | } | ||||
387 | } | ||||
388 | |||||
389 | # Combine lhs (if any) and rhs to get something that matches | ||||
390 | # the syntax of the lookups. | ||||
391 | 9 | 1µs | $property_and_table = "$prefix$table"; | ||
392 | print STDERR __LINE__, ": $property_and_table\n" if DEBUG; | ||||
393 | |||||
394 | # First try stricter matching. | ||||
395 | 9 | 6µs | $file = $utf8::stricter_to_file_of{$property_and_table}; | ||
396 | |||||
397 | # If didn't find it, try again with looser matching by editing | ||||
398 | # out the applicable characters on the rhs and looking up | ||||
399 | # again. | ||||
400 | 9 | 2µs | if (! defined $file) { | ||
401 | 5 | 10µs | 5 | 41µs | $table = _loose_name($table); # spent 41µs making 5 calls to utf8::_loose_name, avg 8µs/call |
402 | 5 | 1µs | $property_and_table = "$prefix$table"; | ||
403 | print STDERR __LINE__, ": $property_and_table\n" if DEBUG; | ||||
404 | 5 | 4µs | $file = $utf8::loose_to_file_of{$property_and_table}; | ||
405 | } | ||||
406 | |||||
407 | # Add the constant and go fetch it in. | ||||
408 | 9 | 2µs | if (defined $file) { | ||
409 | |||||
410 | # A beginning ! means to invert. The 0+ makes sure is | ||||
411 | # numeric | ||||
412 | 9 | 20µs | 9 | 4µs | $invert_it = 0 + $file =~ s/^!//; # spent 4µs making 9 calls to utf8::CORE:subst, avg 422ns/call |
413 | |||||
414 | 9 | 2µs | if ($utf8::why_deprecated{$file}) { | ||
415 | warnings::warnif('deprecated', "Use of '$type' in \\p{} or \\P{} is deprecated because: $utf8::why_deprecated{$file};"); | ||||
416 | } | ||||
417 | |||||
418 | 9 | 1µs | if ($caseless | ||
419 | && exists $utf8::caseless_equivalent{$property_and_table}) | ||||
420 | { | ||||
421 | $file = $utf8::caseless_equivalent{$property_and_table}; | ||||
422 | } | ||||
423 | 9 | 5µs | $file= "$unicore_dir/lib/$file.pl"; | ||
424 | 9 | 9µs | last GETFILE; | ||
425 | } | ||||
426 | print STDERR __LINE__, ": didn't find $property_and_table\n" if DEBUG; | ||||
427 | |||||
428 | ## | ||||
429 | ## Last attempt -- see if it's a standard "To" name | ||||
430 | ## (e.g. "ToLower") ToTitle is used by ucfirst(). | ||||
431 | ## The user-level way to access ToDigit() and ToFold() | ||||
432 | ## is to use Unicode::UCD. | ||||
433 | ## | ||||
434 | # Only check if caller wants non-binary | ||||
435 | my $retried = 0; | ||||
436 | if ($minbits != 1 && $property_and_table =~ s/^to//) {{ | ||||
437 | # Look input up in list of properties for which we have | ||||
438 | # mapping files. | ||||
439 | if (defined ($file = | ||||
440 | $utf8::loose_property_to_file_of{$property_and_table})) | ||||
441 | { | ||||
442 | $type = $utf8::file_to_swash_name{$file}; | ||||
443 | print STDERR __LINE__, ": type set to $type\n" if DEBUG; | ||||
444 | $file = "$unicore_dir/$file.pl"; | ||||
445 | last GETFILE; | ||||
446 | } # If that fails see if there is a corresponding binary | ||||
447 | # property file | ||||
448 | elsif (defined ($file = | ||||
449 | $utf8::loose_to_file_of{$property_and_table})) | ||||
450 | { | ||||
451 | |||||
452 | # Here, there is no map file for the property we are | ||||
453 | # trying to get the map of, but this is a binary | ||||
454 | # property, and there is a file for it that can easily | ||||
455 | # be translated to a mapping. | ||||
456 | |||||
457 | # In the case of properties that are forced to binary, | ||||
458 | # they are a combination. We return the actual | ||||
459 | # mapping instead of the binary. If the input is | ||||
460 | # something like 'Tocjkkiicore', it will be found in | ||||
461 | # %loose_property_to_file_of above as => 'To/kIICore'. | ||||
462 | # But the form like ToIskiicore won't be. To fix | ||||
463 | # this, it was easiest to do it here. These | ||||
464 | # properties are the complements of the default | ||||
465 | # property, so there is an entry in %loose_to_file_of | ||||
466 | # that is 'iskiicore' => '!kIICore/N', If we find such | ||||
467 | # an entry, strip off things and try again, which | ||||
468 | # should find the entry in %loose_property_to_file_of. | ||||
469 | # Actual binary properties that are of this form, such | ||||
470 | # as this entry: 'ishrkt' => '!Perl/Any' will also be | ||||
471 | # retried, but won't be in %loose_property_to_file_of, | ||||
472 | # and instead the next time through, it will find | ||||
473 | # 'hrkt' => '!Perl/Any' and proceed. | ||||
474 | redo if ! $retried | ||||
475 | && $file =~ /^!/ | ||||
476 | && $property_and_table =~ s/^is//; | ||||
477 | |||||
478 | # This is a binary property. Setting this here causes | ||||
479 | # it to be stored as such in the cache, so if someone | ||||
480 | # comes along later looking for just a binary, they | ||||
481 | # get it. | ||||
482 | $minbits = 1; | ||||
483 | |||||
484 | # The 0+ makes sure is numeric | ||||
485 | $invert_it = 0 + $file =~ s/^!//; | ||||
486 | $file = "$unicore_dir/lib/$file.pl"; | ||||
487 | last GETFILE; | ||||
488 | } | ||||
489 | } } | ||||
490 | |||||
491 | ## | ||||
492 | ## If we reach this line, it's because we couldn't figure | ||||
493 | ## out what to do with $type. Ouch. | ||||
494 | ## | ||||
495 | |||||
496 | pop @recursed if @recursed; | ||||
497 | return $type; | ||||
498 | } # end of GETFILE block | ||||
499 | |||||
500 | 9 | 5µs | if (defined $file) { | ||
501 | print STDERR __LINE__, ": found it (file='$file')\n" if DEBUG; | ||||
502 | |||||
503 | ## | ||||
504 | ## If we reach here, it was due to a 'last GETFILE' above | ||||
505 | ## (exception: user-defined properties and mappings), so we | ||||
506 | ## have a filename, so now we load it if we haven't already. | ||||
507 | ## If we have, return the cached results. The cache key is the | ||||
508 | ## class and file to load, and whether the results need to be | ||||
509 | ## inverted. | ||||
510 | ## | ||||
511 | 9 | 12µs | my $found = $Cache{$class, $file, $invert_it}; | ||
512 | 9 | 2µs | if ($found and ref($found) eq $class) { | ||
513 | print STDERR __LINE__, ": Returning cached swash for '$class,$file,$invert_it' for \\p{$type}\n" if DEBUG; | ||||
514 | 2 | 1µs | pop @recursed if @recursed; | ||
515 | 2 | 6µs | return $found; | ||
516 | } | ||||
517 | |||||
518 | 7 | 2µs | local $@; | ||
519 | 7 | 9µs | local $!; | ||
520 | 14 | 1.23ms | $list = do $file; die $@ if $@; | ||
521 | 7 | 11µs | $list_is_from_mktables = 1; | ||
522 | } | ||||
523 | } # End of $type is non-null | ||||
524 | |||||
525 | # Here, either $type was null, or we found the requested property and | ||||
526 | # read it into $list | ||||
527 | |||||
528 | 7 | 2µs | my $extras = ""; | ||
529 | |||||
530 | 7 | 1µs | my $bits = $minbits; | ||
531 | |||||
532 | # mktables lists don't have extras, like '&utf8::prop', so don't need | ||||
533 | # to separate them; also lists are already sorted, so don't need to do | ||||
534 | # that. | ||||
535 | 7 | 2µs | if ($list && ! $list_is_from_mktables) { | ||
536 | my $taint = substr($list,0,0); # maintain taint | ||||
537 | |||||
538 | # Separate the extras from the code point list, and make sure | ||||
539 | # user-defined properties and tr/// are well-behaved for | ||||
540 | # downstream code. | ||||
541 | if ($user_defined || $none) { | ||||
542 | my @tmp = split(/^/m, $list); | ||||
543 | my %seen; | ||||
544 | 2 | 694µs | 2 | 33µs | # spent 22µs (11+11) within utf8::BEGIN@544 which was called:
# once (11µs+11µs) by utf8::AUTOLOAD at line 544 # spent 22µs making 1 call to utf8::BEGIN@544
# spent 11µs making 1 call to warnings::unimport |
545 | |||||
546 | # The extras are anything that doesn't begin with a hex digit. | ||||
547 | $extras = join '', $taint, grep /^[^0-9a-fA-F]/, @tmp; | ||||
548 | |||||
549 | # Remove the extras, and sort the remaining entries by the | ||||
550 | # numeric value of their beginning hex digits, removing any | ||||
551 | # duplicates. | ||||
552 | $list = join '', $taint, | ||||
553 | map { $_->[1] } | ||||
554 | sort { $a->[0] <=> $b->[0] } | ||||
555 | map { /^([0-9a-fA-F]+)/; [ CORE::hex($1), $_ ] } | ||||
556 | grep { /^([0-9a-fA-F]+)/ and not $seen{$1}++ } @tmp; # XXX doesn't do ranges right | ||||
557 | } | ||||
558 | else { | ||||
559 | # mktables has gone to some trouble to make non-user defined | ||||
560 | # properties well-behaved, so we can skip the effort we do for | ||||
561 | # user-defined ones. Any extras are at the very beginning of | ||||
562 | # the string. | ||||
563 | |||||
564 | # This regex splits out the first lines of $list into $1 and | ||||
565 | # strips them off from $list, until we get one that begins | ||||
566 | # with a hex number, alone on the line, or followed by a tab. | ||||
567 | # Either portion may be empty. | ||||
568 | $list =~ s/ \A ( .*? ) | ||||
569 | (?: \z | (?= ^ [0-9a-fA-F]+ (?: \t | $) ) ) | ||||
570 | //msx; | ||||
571 | |||||
572 | $extras = "$taint$1"; | ||||
573 | } | ||||
574 | } | ||||
575 | |||||
576 | 7 | 700ns | if ($none) { | ||
577 | my $hextra = sprintf "%04x", $none + 1; | ||||
578 | $list =~ s/\tXXXX$/\t$hextra/mg; | ||||
579 | } | ||||
580 | |||||
581 | 7 | 2µs | if ($minbits != 1 && $minbits < 32) { # not binary property | ||
582 | my $top = 0; | ||||
583 | while ($list =~ /^([0-9a-fA-F]+)(?:[\t]([0-9a-fA-F]+)?)(?:[ \t]([0-9a-fA-F]+))?/mg) { | ||||
584 | my $min = CORE::hex $1; | ||||
585 | my $max = defined $2 ? CORE::hex $2 : $min; | ||||
586 | my $val = defined $3 ? CORE::hex $3 : 0; | ||||
587 | $val += $max - $min if defined $3; | ||||
588 | $top = $val if $val > $top; | ||||
589 | } | ||||
590 | my $topbits = | ||||
591 | $top > 0xffff ? 32 : | ||||
592 | $top > 0xff ? 16 : 8; | ||||
593 | $bits = $topbits if $bits < $topbits; | ||||
594 | } | ||||
595 | |||||
596 | 7 | 1µs | my @extras; | ||
597 | 7 | 1µs | if ($extras) { | ||
598 | for my $x ($extras) { | ||||
599 | my $taint = substr($x,0,0); # maintain taint | ||||
600 | pos $x = 0; | ||||
601 | while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) { | ||||
602 | my $char = "$1$taint"; | ||||
603 | my $name = "$2$taint"; | ||||
604 | print STDERR __LINE__, ": char [$char] => name [$name]\n" | ||||
605 | if DEBUG; | ||||
606 | if ($char =~ /[-+!&]/) { | ||||
607 | my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really | ||||
608 | my $subobj; | ||||
609 | if ($c eq 'utf8') { | ||||
610 | $subobj = utf8->SWASHNEW($t, "", $minbits, 0); | ||||
611 | } | ||||
612 | elsif (exists &$name) { | ||||
613 | $subobj = utf8->SWASHNEW($name, "", $minbits, 0); | ||||
614 | } | ||||
615 | elsif ($c =~ /^([0-9a-fA-F]+)/) { | ||||
616 | $subobj = utf8->SWASHNEW("", $c, $minbits, 0); | ||||
617 | } | ||||
618 | print STDERR __LINE__, ": returned from getting sub object for $name\n" if DEBUG; | ||||
619 | if (! ref $subobj) { | ||||
620 | pop @recursed if @recursed && $type; | ||||
621 | return $subobj; | ||||
622 | } | ||||
623 | push @extras, $name => $subobj; | ||||
624 | $bits = $subobj->{BITS} if $bits < $subobj->{BITS}; | ||||
625 | $user_defined = $subobj->{USER_DEFINED} | ||||
626 | if $subobj->{USER_DEFINED}; | ||||
627 | } | ||||
628 | } | ||||
629 | } | ||||
630 | } | ||||
631 | |||||
632 | if (DEBUG) { | ||||
633 | print STDERR __LINE__, ": CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none, INVERT_IT => $invert_it, USER_DEFINED => $user_defined"; | ||||
634 | print STDERR "\nLIST =>\n$list" if defined $list; | ||||
635 | print STDERR "\nEXTRAS =>\n$extras" if defined $extras; | ||||
636 | print STDERR "\n"; | ||||
637 | } | ||||
638 | |||||
639 | 7 | 27µs | my $SWASH = bless { | ||
640 | TYPE => $type, | ||||
641 | BITS => $bits, | ||||
642 | EXTRAS => $extras, | ||||
643 | LIST => $list, | ||||
644 | NONE => $none, | ||||
645 | USER_DEFINED => $user_defined, | ||||
646 | @extras, | ||||
647 | } => $class; | ||||
648 | |||||
649 | 7 | 1µs | if ($file) { | ||
650 | 7 | 10µs | $Cache{$class, $file, $invert_it} = $SWASH; | ||
651 | 7 | 3µs | if ($type | ||
652 | && exists $utf8::SwashInfo{$type} | ||||
653 | && exists $utf8::SwashInfo{$type}{'specials_name'}) | ||||
654 | { | ||||
655 | my $specials_name = $utf8::SwashInfo{$type}{'specials_name'}; | ||||
656 | 2 | 150µs | 2 | 32µs | # spent 20µs (8+12) within utf8::BEGIN@656 which was called:
# once (8µs+12µs) by utf8::AUTOLOAD at line 656 # spent 20µs making 1 call to utf8::BEGIN@656
# spent 12µs making 1 call to strict::unimport |
657 | print STDERR "\nspecials_name => $specials_name\n" if DEBUG; | ||||
658 | $SWASH->{'SPECIALS'} = \%$specials_name; | ||||
659 | } | ||||
660 | 7 | 9µs | $SWASH->{'INVERT_IT'} = $invert_it; | ||
661 | } | ||||
662 | |||||
663 | 7 | 4µs | pop @recursed if @recursed && $type; | ||
664 | |||||
665 | 7 | 41µs | return $SWASH; | ||
666 | } | ||||
667 | } | ||||
668 | |||||
669 | # Now SWASHGET is recasted into a C function S_swatch_get (see utf8.c). | ||||
670 | |||||
671 | 1 | 2µs | 1; | ||
sub utf8::CORE:match; # opcode | |||||
# spent 40µs within utf8::CORE:subst which was called 50 times, avg 792ns/call:
# 9 times (15µs+0s) by utf8::SWASHNEW at line 121, avg 2µs/call
# 9 times (12µs+0s) by utf8::SWASHNEW at line 120, avg 1µs/call
# 9 times (4µs+0s) by utf8::SWASHNEW at line 412, avg 422ns/call
# 9 times (3µs+0s) by utf8::SWASHNEW at line 125, avg 378ns/call
# 9 times (3µs+0s) by utf8::SWASHNEW at line 138, avg 322ns/call
# 5 times (2µs+0s) by utf8::_loose_name at line 23, avg 500ns/call |