From 787d93719e61e44aa1ab66c8ecca9cd6ff4fddbf Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 1 Dec 2012 21:12:41 +0200 Subject: Apply realloc optimization to wide string values. --- ChangeLog | 8 ++++++++ eval.c | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6dd4c394..0b2b7f41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-12-01 Arnold D. Robbins + + * eval.c (r_interpret): For op_assign_concat, if both strings + have WSTRCUR, then do the realloc() and append for the + wide string too. Thanks to Janis Papanagnou + for the discussion in + comp.lang.awk. + 2012-11-10 Arnold D. Robbins * Update to bison 2.6.5. Various files regenerated. diff --git a/eval.c b/eval.c index 2421aea1..57411afc 100644 --- a/eval.c +++ b/eval.c @@ -2160,14 +2160,26 @@ post: t1 = force_string(*lhs); t2 = POP_STRING(); - free_wstr(*lhs); - if (t1 != t2 && t1->valref == 1 && (t1->flags & PERM) == 0) { size_t nlen = t1->stlen + t2->stlen; erealloc(t1->stptr, char *, nlen + 2, "r_interpret"); memcpy(t1->stptr + t1->stlen, t2->stptr, t2->stlen); t1->stlen = nlen; t1->stptr[nlen] = '\0'; + +#if MBS_SUPPORT + if ((t1->flags & WSTRCUR) != 0 && (t2->flags & WSTRCUR) != 0) { + size_t wlen = t1->wstlen + t2->wstlen; + + erealloc(t1->wstptr, wchar_t *, + sizeof(wchar_t) * (wlen + 2), "r_interpret"); + memcpy(t1->wstptr + t1->wstlen, t2->wstptr, t2->wstlen); + t1->wstlen = wlen; + t1->wstptr[wlen] = L'\0'; + t1->flags |= WSTRCUR; + } else + free_wstr(*lhs); +#endif } else { size_t nlen = t1->stlen + t2->stlen; char *p; -- cgit v1.2.3