Commit 191ec640 by Ilya Tocar Committed by Ilya Tocar

Remove unnecessary calls to strchr.

gcc/
	* gcc.c (handle_foffload_option): Remove unnecessary calls to strchr,
	strlen, strncpy.
	* lto-wrapper.c (append_offload_options): Likewise.


Co-Authored-By: Jakub Jelinek <jakub@redhat.com>

From-SVN: r218044
parent a959b33f
2014-11-25 Ilya Tocar <ilya.tocar@intel.com>
Jakub Jelinek <jakub@redhat.com>
* gcc.c (handle_foffload_option): Remove unnecessary calls to strchr,
strlen, strncpy.
* lto-wrapper.c (append_offload_options): Likewise.
2014-11-25 Eric Botcazou <ebotcazou@adacore.com> 2014-11-25 Eric Botcazou <ebotcazou@adacore.com>
* config/rs6000/rs6000.c (rs6000_call_aix): For the AIX ABI, do not * config/rs6000/rs6000.c (rs6000_call_aix): For the AIX ABI, do not
...@@ -3384,11 +3384,11 @@ handle_foffload_option (const char *arg) ...@@ -3384,11 +3384,11 @@ handle_foffload_option (const char *arg)
{ {
next = strchr (cur, ','); next = strchr (cur, ',');
if (next == NULL) if (next == NULL)
next = strchr (cur, '\0'); next = end;
next = (next > end) ? end : next; next = (next > end) ? end : next;
target = XNEWVEC (char, next - cur + 1); target = XNEWVEC (char, next - cur + 1);
strncpy (target, cur, next - cur); memcpy (target, cur, next - cur);
target[next - cur] = '\0'; target[next - cur] = '\0';
/* If 'disable' is passed to the option, stop parsing the option and clean /* If 'disable' is passed to the option, stop parsing the option and clean
...@@ -3408,8 +3408,7 @@ handle_foffload_option (const char *arg) ...@@ -3408,8 +3408,7 @@ handle_foffload_option (const char *arg)
if (n == NULL) if (n == NULL)
n = strchr (c, '\0'); n = strchr (c, '\0');
if (strlen (target) == (size_t) (n - c) if (next - cur == n - c && strncmp (target, c, n - c) == 0)
&& strncmp (target, c, n - c) == 0)
break; break;
c = *n ? n + 1 : NULL; c = *n ? n + 1 : NULL;
...@@ -3420,7 +3419,10 @@ handle_foffload_option (const char *arg) ...@@ -3420,7 +3419,10 @@ handle_foffload_option (const char *arg)
target); target);
if (!offload_targets) if (!offload_targets)
offload_targets = xstrdup (target); {
offload_targets = target;
target = NULL;
}
else else
{ {
/* Check that the target hasn't already presented in the list. */ /* Check that the target hasn't already presented in the list. */
...@@ -3431,8 +3433,7 @@ handle_foffload_option (const char *arg) ...@@ -3431,8 +3433,7 @@ handle_foffload_option (const char *arg)
if (n == NULL) if (n == NULL)
n = strchr (c, '\0'); n = strchr (c, '\0');
if (strlen (target) == (size_t) (n - c) if (next - cur == n - c && strncmp (c, target, n - c) == 0)
&& strncmp (c, target, n - c) == 0)
break; break;
c = n + 1; c = n + 1;
...@@ -3442,12 +3443,13 @@ handle_foffload_option (const char *arg) ...@@ -3442,12 +3443,13 @@ handle_foffload_option (const char *arg)
/* If duplicate is not found, append the target to the list. */ /* If duplicate is not found, append the target to the list. */
if (c > n) if (c > n)
{ {
size_t offload_targets_len = strlen (offload_targets);
offload_targets offload_targets
= XRESIZEVEC (char, offload_targets, = XRESIZEVEC (char, offload_targets,
strlen (offload_targets) + strlen (target) + 2); offload_targets_len + next - cur + 2);
if (strlen (offload_targets) != 0) if (offload_targets_len)
strcat (offload_targets, ":"); offload_targets[offload_targets_len++] = ':';
strcat (offload_targets, target); memcpy (offload_targets + offload_targets_len, target, next - cur);
} }
} }
......
...@@ -587,7 +587,7 @@ append_offload_options (obstack *argv_obstack, const char *target, ...@@ -587,7 +587,7 @@ append_offload_options (obstack *argv_obstack, const char *target,
{ {
next = strchr (cur, ','); next = strchr (cur, ',');
if (next == NULL) if (next == NULL)
next = strchr (cur, '\0'); next = opts;
next = (next > opts) ? opts : next; next = (next > opts) ? opts : next;
if (strlen (target) == (size_t) (next - cur) if (strlen (target) == (size_t) (next - cur)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment