Skip to content

Commit

Permalink
[str] Simplified Parrot_str_concat() to avoid creating more STRING he…
Browse files Browse the repository at this point in the history
…aders than

necessary; this ought to improve performance in loops that HLLs often produce.
It's less code, anyhow.

git-svn-id: https://svn.parrot.org/parrot/trunk@44041 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
chromatic committed Feb 16, 2010
1 parent c6ece91 commit 45e3627
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/string/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,21 +496,9 @@ Parrot_str_concat(PARROT_INTERP, ARGIN_NULLOK(STRING *a),
ASSERT_ARGS(Parrot_str_concat)
if (a && a->strlen) {
if (b && b->strlen) {
const ENCODING *enc;
const CHARSET *cs = string_rep_compatible(interp, a, b, &enc);
STRING *result;

if (!cs) {
cs = a->charset;
enc = a->encoding;
}
result = Parrot_str_new_init(interp, NULL, a->bufused + b->bufused,
enc, cs, 0);

result = Parrot_str_append(interp, result, a);
result = Parrot_str_append(interp, result, b);

return result;
STRING *result = Parrot_str_copy(interp, a);
Parrot_str_write_COW(interp, result);
return Parrot_str_append(interp, result, b);
}

return Parrot_str_copy(interp, a);
Expand Down Expand Up @@ -573,10 +561,10 @@ Parrot_str_append(PARROT_INTERP, ARGMOD_NULLOK(STRING *a), ARGIN_NULLOK(STRING *
}
else {
/* upgrade strings for concatenation */
enc = (a->encoding == Parrot_utf16_encoding_ptr ||
b->encoding == Parrot_utf16_encoding_ptr ||
a->encoding == Parrot_ucs2_encoding_ptr ||
b->encoding == Parrot_ucs2_encoding_ptr)
enc = (a->encoding == Parrot_utf16_encoding_ptr
|| b->encoding == Parrot_utf16_encoding_ptr
|| a->encoding == Parrot_ucs2_encoding_ptr
|| b->encoding == Parrot_ucs2_encoding_ptr)
? Parrot_utf16_encoding_ptr
: Parrot_utf8_encoding_ptr;

Expand Down

0 comments on commit 45e3627

Please sign in to comment.