This small inline function does what my code was doing manually in a
couple of places. Should be no functional difference, just makes the code
tidier.
Suggested by Karl.
aux[PERL_MULTICONCAT_IX_UTF8_LEN].size = ulen;
for (n = 0; n < (nargs + 1); n++) {
aux[PERL_MULTICONCAT_IX_UTF8_LEN].size = ulen;
for (n = 0; n < (nargs + 1); n++) {
- SSize_t l, ul, i;
- l = ul = (lens++)->size;
- for (i = 0; i < l; i++) {
+ SSize_t i;
+ char * orig_up = up;
+ for (i = (lens++)->size; i > 0; i--) {
- if (UTF8_IS_INVARIANT(c))
- *up++ = c;
- else {
- *up++ = UTF8_EIGHT_BIT_HI(c);
- *up++ = UTF8_EIGHT_BIT_LO(c);
- ul++;
- }
+ append_utf8_from_native_byte(c, (U8**)&up);
+ (ulens++)->size = (i < 0) ? i : up - orig_up;
len = -len;
if (UNLIKELY(p)) {
/* copy plain-but-variant pv to a utf8 targ */
len = -len;
if (UNLIKELY(p)) {
/* copy plain-but-variant pv to a utf8 targ */
+ char * end_pv = dsv_pv + len;
+ while (dsv_pv < end_pv) {
- if (UTF8_IS_INVARIANT(c))
- *dsv_pv++ = c;
- else {
- *dsv_pv++ = UTF8_EIGHT_BIT_HI(c);
- *dsv_pv++ = UTF8_EIGHT_BIT_LO(c);
- len--;
- }
+ append_utf8_from_native_byte(c, (U8**)&dsv_pv);