This function does two passes over the input. In the first it decides
if the string can be downgraded, and computes the size needed for the
downgraded string. In the 2nd pass, it does the conversion.
Adding a single 'if' to the function can bypass the 2nd pass completely
if only invariants are found. The 2nd pass is replaced by a memcpy().
*is_utf8 = FALSE;
Newx(d, (*len) - count + 1, U8);
+
+ if (LIKELY(count)) {
s = start; start = d;
while (s < send) {
U8 c = *s++;
}
*d = '\0';
*len = d - start;
+
return (U8 *)start;
+ }
+ else {
+ Copy(start, d, *len, U8);
+ *(d + *len) = '\0';
+ return (U8 *)d;
+ }
}
/*