* strcat and config/darwin.c
@ 2003-01-26 17:02 Andrew Pinski
2003-01-28 11:02 ` Richard Henderson
2003-02-02 22:49 ` [PATCH] " Andrew Pinski
0 siblings, 2 replies; 5+ messages in thread
From: Andrew Pinski @ 2003-01-26 17:02 UTC (permalink / raw)
To: gcc-patches, gcc, apinski; +Cc: Andrew Pinski
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
In config/darwin.c, there are places which strcat is used even though
it is easy and faster to find where the end of the string is, here is
a patch to change all the strcats to strcpy.
2003-01-25 Andrew Pinski <pinskia@physics.uc.edu>
* config/darwin.c: (machopic_non_lazy_ptr_name): Change strcat to
strcpy with length added.
(machopic_stub_name): Likewise.
[-- Attachment #2: temp.diff --]
[-- Type: application/octet-stream, Size: 1883 bytes --]
--- ../../../../gcc-clean/src/gcc/config/darwin.c Sat Jan 25 15:19:38 2003
+++ ./darwin.c Sun Jan 26 04:33:42 2003
@@ -295,19 +295,24 @@
{
char *buffer;
tree ptr_name;
+ int len_name = strlen (name);
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (len_name + 20);
strcpy (buffer, "&L");
if (name[0] == '*')
- strcat (buffer, name+1);
+ {
+ strcpy (buffer+2, name+1);
+ len_name-=1;
+ }
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ strcpy (buffer+2, "_");
+ strcpy (buffer+3, name);
+ len_name+=1;
}
- strcat (buffer, "$non_lazy_ptr");
+ strcpy (buffer + 2 + len_name, "$non_lazy_ptr");
ptr_name = get_identifier (buffer);
machopic_non_lazy_pointers
@@ -354,27 +359,37 @@
char *buffer;
tree ptr_name;
int needs_quotes = name_needs_quotes (name);
+ int len = 0;
+ int name_len = strlen (name);
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (name_len + 20);
if (needs_quotes)
- strcpy (buffer, "&\"L");
+ {
+ strcpy (buffer, "&\"L");
+ len = strlen ("&\"L");
+ }
else
- strcpy (buffer, "&L");
+ {
+ strcpy (buffer, "&L");
+ len = strlen ("&L");
+ }
if (name[0] == '*')
{
- strcat (buffer, name+1);
+ strcpy (buffer + len, name+1);
+ len += name_len - 1;
}
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ strcpy (buffer+len, "_");
+ strcpy (buffer+len+1, name);
+ len+=name_len+1;
}
if (needs_quotes)
- strcat (buffer, "$stub\"");
+ strcpy (buffer+len, "$stub\"");
else
- strcat (buffer, "$stub");
+ strcpy (buffer+len, "$stub");
ptr_name = get_identifier (buffer);
machopic_stubs = tree_cons (ptr_name, ident, machopic_stubs);
[-- Attachment #3: Type: text/plain, Size: 64 bytes --]
Thanks,
Andrew Pinski
apinski@apple.com
pinskia@physics.uc.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: strcat and config/darwin.c
2003-01-26 17:02 strcat and config/darwin.c Andrew Pinski
@ 2003-01-28 11:02 ` Richard Henderson
2003-02-02 22:49 ` [PATCH] " Andrew Pinski
1 sibling, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2003-01-28 11:02 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches, gcc, apinski
On Sun, Jan 26, 2003 at 04:50:50AM -0800, Andrew Pinski wrote:
> In config/darwin.c, there are places which strcat is used even though
> it is easy and faster to find where the end of the string is, here is
> a patch to change all the strcats to strcpy.
It's also possible to use memcpy here as well. The length
of the string is still available from the call to alloca.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Re: strcat and config/darwin.c
2003-01-26 17:02 strcat and config/darwin.c Andrew Pinski
2003-01-28 11:02 ` Richard Henderson
@ 2003-02-02 22:49 ` Andrew Pinski
2003-02-03 6:32 ` Andrew Pinski
1 sibling, 1 reply; 5+ messages in thread
From: Andrew Pinski @ 2003-02-02 22:49 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches, gcc, apinski
[-- Attachment #1: Type: text/plain, Size: 335 bytes --]
Here is an updated with the suggestion from Richard Henderson by it
using memcpy instead of strcpy:
2003-02-02 Andrew Pinski <pinskia@physics.uc.edu>
* config/darwin.c: (machopic_non_lazy_ptr_name): Change strcat to
memcpy with length added.
(machopic_stub_name): Likewise. (machopic_classify_ident): Change
strcpy to memcpy.
[-- Attachment #2: temp.diff --]
[-- Type: application/octet-stream, Size: 2557 bytes --]
--- darwin.c Sun Feb 2 08:10:37 2003
+++ ../../../../gcc-clean/src/gcc/config/darwin.c Sat Jan 25 15:19:38 2003
@@ -124,9 +124,8 @@ machopic_classify_ident (ident)
else if (name[1] == 'd' || name[1] == 't')
{
char *new_name;
- int name_len = strlen (name);
- new_name = (char *)alloca (name_len + 1);
- memcpy (new_name, name, name_len);
+ new_name = (char *)alloca (strlen (name) + 1);
+ strcpy (new_name, name);
new_name[1] = (name[1] == 'd') ? 'D' : 'T';
if (maybe_get_identifier (new_name) != NULL)
return (name[1] == 'd') ? MACHOPIC_DEFINED_DATA
@@ -296,24 +295,19 @@ machopic_non_lazy_ptr_name (name)
{
char *buffer;
tree ptr_name;
- int len_name = strlen (name);
- buffer = alloca ( len_name + 20);
+ buffer = alloca (strlen (name) + 20);
- memcpy (buffer, "&L", 2);
+ strcpy (buffer, "&L");
if (name[0] == '*')
- {
- memcpy (buffer + 2, name + 1, len_name);
- len_name -= 1;
- }
+ strcat (buffer, name+1);
else
{
- memcpy (buffer + 2, "_", 1);
- memcpy (buffer + 3, name, len_name + 1);
- len_name += 1;
+ strcat (buffer, "_");
+ strcat (buffer, name);
}
- memcpy (buffer + 2 + len_name, "$non_lazy_ptr", strlen ("$non_lazy_ptr") + 1);
+ strcat (buffer, "$non_lazy_ptr");
ptr_name = get_identifier (buffer);
machopic_non_lazy_pointers
@@ -360,37 +354,27 @@ machopic_stub_name (name)
char *buffer;
tree ptr_name;
int needs_quotes = name_needs_quotes (name);
- int len=0;
- int name_len = strlen (name);
- buffer = alloca (name_len + 20);
+ buffer = alloca (strlen (name) + 20);
if (needs_quotes)
- {
- len = 3;
- memcpy (buffer, "&\"L", len);
- }
+ strcpy (buffer, "&\"L");
else
- {
- len = 2;
- memcpy (buffer, "&L", len);
- }
+ strcpy (buffer, "&L");
if (name[0] == '*')
{
- len += name_len-1;
- memcpy (buffer+len, name+1, name_len);
+ strcat (buffer, name+1);
}
else
{
- memcpy (buffer + len, "_", 1);
- memcpy (buffer + len + 1, name, name_len);
- len += name_len+1;
+ strcat (buffer, "_");
+ strcat (buffer, name);
}
if (needs_quotes)
- memcpy (buffer + len, "$stub\"", 7);
+ strcat (buffer, "$stub\"");
else
- memcpy (buffer + len, "$stub", 6);
+ strcat (buffer, "$stub");
ptr_name = get_identifier (buffer);
machopic_stubs = tree_cons (ptr_name, ident, machopic_stubs);
[-- Attachment #3: Type: text/plain, Size: 611 bytes --]
Thanks,
Andrew Pinski
apinski@apple.com
pinskia@physics.uc.edu
On Sunday, Jan 26, 2003, at 04:50 US/Pacific, Andrew Pinski wrote:
> In config/darwin.c, there are places which strcat is used even though
> it is easy and faster to find where the end of the string is, here is
> a patch to change all the strcats to strcpy.
>
>
> 2003-01-25 Andrew Pinski <pinskia@physics.uc.edu>
>
> * config/darwin.c: (machopic_non_lazy_ptr_name): Change strcat to
> strcpy with length added.
> (machopic_stub_name): Likewise.
>
>
> <temp.diff>
>
> Thanks,
> Andrew Pinski
> apinski@apple.com
> pinskia@physics.uc.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Re: strcat and config/darwin.c
2003-02-02 22:49 ` [PATCH] " Andrew Pinski
@ 2003-02-03 6:32 ` Andrew Pinski
2003-10-05 1:12 ` Andrew Pinski
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Pinski @ 2003-02-03 6:32 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches, gcc, apinski
[-- Attachment #1: Type: text/plain, Size: 142 bytes --]
I messed up the patch, in machopic_classify_ident, I forgot to add one
to the length to copy the null character.
Here is an updated patch:
[-- Attachment #2: darwin.str.diff --]
[-- Type: application/octet-stream, Size: 2563 bytes --]
--- ../../../../gcc-clean/src/gcc/config/darwin.c Sat Jan 25 15:19:38 2003
+++ ./darwin.c Sun Feb 2 22:19:53 2003
@@ -124,8 +124,9 @@ machopic_classify_ident (ident)
else if (name[1] == 'd' || name[1] == 't')
{
char *new_name;
- new_name = (char *)alloca (strlen (name) + 1);
- strcpy (new_name, name);
+ int name_len = strlen (name);
+ new_name = (char *)alloca (name_len + 1);
+ memcpy (new_name, name, name_len + 1);
new_name[1] = (name[1] == 'd') ? 'D' : 'T';
if (maybe_get_identifier (new_name) != NULL)
return (name[1] == 'd') ? MACHOPIC_DEFINED_DATA
@@ -295,19 +296,24 @@ machopic_non_lazy_ptr_name (name)
{
char *buffer;
tree ptr_name;
+ int len_name = strlen (name);
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca ( len_name + 20);
- strcpy (buffer, "&L");
+ memcpy (buffer, "&L", 2);
if (name[0] == '*')
- strcat (buffer, name+1);
+ {
+ memcpy (buffer + 2, name + 1, len_name);
+ len_name -= 1;
+ }
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ memcpy (buffer + 2, "_", 1);
+ memcpy (buffer + 3, name, len_name + 1);
+ len_name += 1;
}
- strcat (buffer, "$non_lazy_ptr");
+ memcpy (buffer + 2 + len_name, "$non_lazy_ptr", strlen ("$non_lazy_ptr") + 1);
ptr_name = get_identifier (buffer);
machopic_non_lazy_pointers
@@ -354,27 +360,37 @@ machopic_stub_name (name)
char *buffer;
tree ptr_name;
int needs_quotes = name_needs_quotes (name);
+ int len=0;
+ int name_len = strlen (name);
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (name_len + 20);
if (needs_quotes)
- strcpy (buffer, "&\"L");
+ {
+ len = 3;
+ memcpy (buffer, "&\"L", len);
+ }
else
- strcpy (buffer, "&L");
+ {
+ len = 2;
+ memcpy (buffer, "&L", len);
+ }
if (name[0] == '*')
{
- strcat (buffer, name+1);
+ len += name_len-1;
+ memcpy (buffer+len, name+1, name_len);
}
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ memcpy (buffer + len, "_", 1);
+ memcpy (buffer + len + 1, name, name_len);
+ len += name_len+1;
}
if (needs_quotes)
- strcat (buffer, "$stub\"");
+ memcpy (buffer + len, "$stub\"", 7);
else
- strcat (buffer, "$stub");
+ memcpy (buffer + len, "$stub", 6);
ptr_name = get_identifier (buffer);
machopic_stubs = tree_cons (ptr_name, ident, machopic_stubs);
[-- Attachment #3: Type: text/plain, Size: 575 bytes --]
Thanks,
Andrew Pinski
apinski@apple.com
pinskia@physics.uc.edu
On Sunday, Feb 2, 2003, at 14:49 US/Pacific, Andrew Pinski wrote:
> Here is an updated with the suggestion from Richard Henderson by it
> using memcpy instead of strcpy:
>
> 2003-02-02 Andrew Pinski <pinskia@physics.uc.edu>
>
> * config/darwin.c: (machopic_non_lazy_ptr_name): Change strcat to
> memcpy with length added.
> (machopic_stub_name): Likewise. (machopic_classify_ident): Change
> strcpy to memcpy.
> <temp.diff>
>
> Thanks,
> Andrew Pinski
> apinski@apple.com
> pinskia@physics.uc.edu
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Re: strcat and config/darwin.c
2003-02-03 6:32 ` Andrew Pinski
@ 2003-10-05 1:12 ` Andrew Pinski
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2003-10-05 1:12 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches, gcc, apinski
[-- Attachment #1: Type: text/plain, Size: 2908 bytes --]
This is really just a ping but it has been updated and changed some
variable names in the patch.
This is also a simple speedup.
ChangeLog:
* config/darwin.c: (machopic_non_lazy_ptr_name): Change strcat to
memcpy and add length together.
(machopic_stub_name): Likewise. (machopic_classify_ident): Change
strcpy to memcpy.
Patch:
Index: darwin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.c,v
retrieving revision 1.46
diff -u -p -r1.46 darwin.c
--- darwin.c 27 Sep 2003 04:48:11 -0000 1.46
+++ darwin.c 5 Oct 2003 01:03:38 -0000
@@ -294,20 +294,28 @@ machopic_non_lazy_ptr_name (const char *
{
char *buffer;
+ int namelen = strlen (name);
+ int bufferlen = 0;
tree ptr_name;
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (namelen + strlen("$non_lazy_ptr") + 5);
strcpy (buffer, "&L");
+ bufferlen = 2;
if (name[0] == '*')
- strcat (buffer, name+1);
+ {
+ memcpy (buffer+bufferlen, name+1, namelen-1+1);
+ bufferlen += namelen-1;
+ }
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ buffer[bufferlen] = '_';
+ memcpy (buffer+bufferlen+1, name, namelen+1);
+ bufferlen += namelen;
}
- strcat (buffer, "$non_lazy_ptr");
+ memcpy (buffer + bufferlen, "$non_lazy_ptr",
strlen("$non_lazy_ptr")+1);
+ bufferlen += strlen("$non_lazy_ptr");
ptr_name = get_identifier (buffer);
machopic_non_lazy_pointers
@@ -351,29 +359,46 @@ machopic_stub_name (const char *name)
{
char *buffer;
+ int bufferlen = 0;
+ int namelen = strlen (name);
tree ptr_name;
int needs_quotes = name_needs_quotes (name);
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (namelen + 20);
if (needs_quotes)
- strcpy (buffer, "&\"L");
+ {
+ strcpy (buffer, "&\"L");
+ bufferlen = strlen("&\"L");
+ }
else
- strcpy (buffer, "&L");
+ {
+ strcpy (buffer, "&L");
+ bufferlen = strlen("&L");
+ }
+
if (name[0] == '*')
{
- strcat (buffer, name+1);
+ memcpy (buffer + bufferlen, name+1, namelen - 1 +1);
+ bufferlen += namelen - 1;
}
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ buffer[bufferlen] = '_';
+ memcpy (buffer + bufferlen +1, name, namelen+1);
+ bufferlen += namelen;
}
if (needs_quotes)
- strcat (buffer, "$stub\"");
+ {
+ memcpy (buffer + bufferlen, "$stub\"", strlen("$stub\""));
+ bufferlen += strlen("$stub\"");
+ }
else
- strcat (buffer, "$stub");
+ {
+ memcpy (buffer + bufferlen, "$stub", strlen("$stub"));
+ bufferlen += strlen("$stub");
+ }
ptr_name = get_identifier (buffer);
machopic_stubs = tree_cons (ptr_name, ident, machopic_stubs);
[-- Attachment #2: strcat.diff --]
[-- Type: application/octet-stream, Size: 2554 bytes --]
Index: darwin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.c,v
retrieving revision 1.46
diff -u -p -r1.46 darwin.c
--- darwin.c 27 Sep 2003 04:48:11 -0000 1.46
+++ darwin.c 5 Oct 2003 01:03:38 -0000
@@ -294,20 +294,28 @@ machopic_non_lazy_ptr_name (const char *
{
char *buffer;
+ int namelen = strlen (name);
+ int bufferlen = 0;
tree ptr_name;
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (namelen + strlen("$non_lazy_ptr") + 5);
strcpy (buffer, "&L");
+ bufferlen = 2;
if (name[0] == '*')
- strcat (buffer, name+1);
+ {
+ memcpy (buffer+bufferlen, name+1, namelen-1+1);
+ bufferlen += namelen-1;
+ }
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ buffer[bufferlen] = '_';
+ memcpy (buffer+bufferlen+1, name, namelen+1);
+ bufferlen += namelen;
}
- strcat (buffer, "$non_lazy_ptr");
+ memcpy (buffer + bufferlen, "$non_lazy_ptr", strlen("$non_lazy_ptr")+1);
+ bufferlen += strlen("$non_lazy_ptr");
ptr_name = get_identifier (buffer);
machopic_non_lazy_pointers
@@ -351,29 +359,46 @@ machopic_stub_name (const char *name)
{
char *buffer;
+ int bufferlen = 0;
+ int namelen = strlen (name);
tree ptr_name;
int needs_quotes = name_needs_quotes (name);
- buffer = alloca (strlen (name) + 20);
+ buffer = alloca (namelen + 20);
if (needs_quotes)
- strcpy (buffer, "&\"L");
+ {
+ strcpy (buffer, "&\"L");
+ bufferlen = strlen("&\"L");
+ }
else
- strcpy (buffer, "&L");
+ {
+ strcpy (buffer, "&L");
+ bufferlen = strlen("&L");
+ }
+
if (name[0] == '*')
{
- strcat (buffer, name+1);
+ memcpy (buffer + bufferlen, name+1, namelen - 1 +1);
+ bufferlen += namelen - 1;
}
else
{
- strcat (buffer, "_");
- strcat (buffer, name);
+ buffer[bufferlen] = '_';
+ memcpy (buffer + bufferlen +1, name, namelen+1);
+ bufferlen += namelen;
}
if (needs_quotes)
- strcat (buffer, "$stub\"");
+ {
+ memcpy (buffer + bufferlen, "$stub\"", strlen("$stub\""));
+ bufferlen += strlen("$stub\"");
+ }
else
- strcat (buffer, "$stub");
+ {
+ memcpy (buffer + bufferlen, "$stub", strlen("$stub"));
+ bufferlen += strlen("$stub");
+ }
ptr_name = get_identifier (buffer);
machopic_stubs = tree_cons (ptr_name, ident, machopic_stubs);
[-- Attachment #3: Type: text/plain, Size: 3 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-10-05 1:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-26 17:02 strcat and config/darwin.c Andrew Pinski
2003-01-28 11:02 ` Richard Henderson
2003-02-02 22:49 ` [PATCH] " Andrew Pinski
2003-02-03 6:32 ` Andrew Pinski
2003-10-05 1:12 ` Andrew Pinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).