Bug 16405 - do_paste redundant strlen
Summary: do_paste redundant strlen
Alias: None
Product: R
Classification: Unclassified
Component: Low-level (show other bugs)
Version: R 3.2.0
Hardware: All All
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2015-06-01 07:22 UTC by talhayon1
Modified: 2015-06-01 07:22 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description talhayon1 2015-06-01 07:22:58 UTC
do_paste uses strlen after using strcpy to advance the string to its end.

This is a waste since there exists stpcpy which does this exact same thing in linux (for windows one can actually write the actual function).

It means there are actually three passes over the data instead of two (or three in the collapse case).

You can see it here:

if (use_UTF8) {
  s = translateCharUTF8(cs);
  strcpy(buf, s);
  buf += strlen(s);
} else {
  s = use_Bytes ? CHAR(cs) : translateChar(cs);
  strcpy(buf, s);
  buf += strlen(s);
  allKnown = allKnown && (strIsASCII(s) || (ENC_KNOWN(cs)> 0));
  anyKnown = anyKnown || (ENC_KNOWN(cs)> 0);