- my $else= ( $opt{else} ||= 0 );
- for my $size ( @size ) {
- my $optree= $self->$method( %opt, type => $type, max_depth => $size );
- my $cond= "((e)-(s) > " . ( $size - 1 ).")";
- $else= __cond_join( $cond, $optree, $else );
+ # If we want the UTF-8 invariants, get those.
+ my $low;
+ if ($opt{type} !~ /non_low|high/
+ && ($low= $self->make_trie( 'low', 1)))
+ {
+ $low= $self->_optree( $low, 'depth', $opt{ret_type}, 0, 0 );
+
+ # Expand out the UTF-8 invariants as a string so that we
+ # can use them as the conditional
+ $low = $self->_cond_as_str( $low, 0, \%opt);
+
+ # If there are Latin1 variants, add a test for them.
+ if ($latin1) {
+ $else = __cond_join("(! is_utf8 )", $latin1, $else);
+ }
+ elsif ($method eq 'generic_optree') {
+
+ # Otherwise for 'generic' only we know that what
+ # follows must be valid for just UTF-8 strings,
+ $else->{test} = "( is_utf8 && $else->{test} )";
+ }
+
+ # If the invariants match, we are done; otherwise we have
+ # to go to the 'else' clause.
+ $else = __cond_join($low, 1, $else);
+ }
+ elsif ($latin1) { # Here, didn't want or didn't have invariants,
+ # but we do have latin variants
+ $else = __cond_join("(! is_utf8)", $latin1, $else);
+ }
+
+ # We need at least one byte available to start off the tests
+ $else = __cond_join("LIKELY((e) > (s))", $else, 0);
+ }
+ else { # Here, we don't want or there aren't any variants. A single
+ # byte available is enough.
+ my $cond= "((e) > (s))";
+ my $optree = $self->$method(%opt);
+ $else= __cond_join( $cond, $optree, $else );
+ }