* [RFA] gdbserver/server.c: Replace 2x strlen() by a variable
@ 2006-12-21 7:45 Markus Deuling
2006-12-21 11:08 ` Joel Brobecker
0 siblings, 1 reply; 6+ messages in thread
From: Markus Deuling @ 2006-12-21 7:45 UTC (permalink / raw)
To: GDB Patches
Hello,
this little patch adds a variable to prevent strlen() from being called two times.
Maybe it would also be a good idea to replace it by the hard-coded length, but I think
the code then will be less readable then.
Is it ok to apply ?
ChangeLog:
* server.c (handle_general_set): New variable len instead
of using strlen two times.
=========================================
diff -urN src/gdb/gdbserver/server.c dev/gdb/gdbserver/server.c
--- src/gdb/gdbserver/server.c 2006-12-21 08:38:11.000000000 +0100
+++ dev/gdb/gdbserver/server.c 2006-12-21 08:38:25.000000000 +0100
@@ -163,10 +163,11 @@
void
handle_general_set (char *own_buf)
{
- if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
+ int len = strlen ("QPassSignals:");
+ if (strncmp ("QPassSignals:", own_buf, len) == 0)
{
int numsigs = (int) TARGET_SIGNAL_LAST, i;
- const char *p = own_buf + strlen ("QPassSignals:");
+ const char *p = own_buf + len;
CORE_ADDR cursig;
p = decode_address_to_semicolon (&cursig, p);
Regards,
Markus
--
Markus Deuling
GNU Toolchain for Linux on Cell BE
deuling@de.ibm.com
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [RFA] gdbserver/server.c: Replace 2x strlen() by a variable
2006-12-21 7:45 [RFA] gdbserver/server.c: Replace 2x strlen() by a variable Markus Deuling
@ 2006-12-21 11:08 ` Joel Brobecker
2006-12-21 11:48 ` Andreas Schwab
2006-12-21 12:47 ` Mark Kettenis
0 siblings, 2 replies; 6+ messages in thread
From: Joel Brobecker @ 2006-12-21 11:08 UTC (permalink / raw)
To: Markus Deuling; +Cc: GDB Patches
> ChangeLog:
>
> * server.c (handle_general_set): New variable len instead
> of using strlen two times.
Actually, since the same string is duplicated a couple of times,
I would also suggest declaring a constant string "QPassSignals:"
and use the constant instead of risking a typo... How about:
const char str[] = "QPassSignals:";
and then use "sizeof (str) - 1". Is that bad coding style? Otherwise,
you can declare your sale constant:
const int len = strlen (str);
I am not reviewer, so these are just suggestions, not a request (JIC).
> =========================================
> diff -urN src/gdb/gdbserver/server.c dev/gdb/gdbserver/server.c
> --- src/gdb/gdbserver/server.c 2006-12-21 08:38:11.000000000 +0100
> +++ dev/gdb/gdbserver/server.c 2006-12-21 08:38:25.000000000 +0100
> @@ -163,10 +163,11 @@
> void
> handle_general_set (char *own_buf)
> {
> - if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
> + int len = strlen ("QPassSignals:");
> + if (strncmp ("QPassSignals:", own_buf, len) == 0)
> {
> int numsigs = (int) TARGET_SIGNAL_LAST, i;
> - const char *p = own_buf + strlen ("QPassSignals:");
> + const char *p = own_buf + len;
> CORE_ADDR cursig;
>
> p = decode_address_to_semicolon (&cursig, p);
>
> Regards,
> Markus
>
> --
> Markus Deuling
> GNU Toolchain for Linux on Cell BE
> deuling@de.ibm.com
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [RFA] gdbserver/server.c: Replace 2x strlen() by a variable
2006-12-21 11:08 ` Joel Brobecker
@ 2006-12-21 11:48 ` Andreas Schwab
2006-12-21 12:47 ` Mark Kettenis
1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2006-12-21 11:48 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Markus Deuling, GDB Patches
Joel Brobecker <brobecker@adacore.com> writes:
>> ChangeLog:
>>
>> * server.c (handle_general_set): New variable len instead
>> of using strlen two times.
>
> Actually, since the same string is duplicated a couple of times,
> I would also suggest declaring a constant string "QPassSignals:"
> and use the constant instead of risking a typo... How about:
>
> const char str[] = "QPassSignals:";
Or just define it as a macro.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA] gdbserver/server.c: Replace 2x strlen() by a variable
2006-12-21 11:08 ` Joel Brobecker
2006-12-21 11:48 ` Andreas Schwab
@ 2006-12-21 12:47 ` Mark Kettenis
2006-12-21 13:04 ` Joel Brobecker
1 sibling, 1 reply; 6+ messages in thread
From: Mark Kettenis @ 2006-12-21 12:47 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Markus Deuling, GDB Patches
> > ChangeLog:
> >
> > * server.c (handle_general_set): New variable len instead
> > of using strlen two times.
>
> Actually, since the same string is duplicated a couple of times,
> I would also suggest declaring a constant string "QPassSignals:"
> and use the constant instead of risking a typo... How about:
>
> const char str[] = "QPassSignals:";
>
> and then use "sizeof (str) - 1". Is that bad coding style? Otherwise,
> you can declare your sale constant:
>
> const int len = strlen (str);
>
> I am not reviewer, so these are just suggestions, not a request (JIC).
I'm pretty sure GCC will optimize away the strlen("QPassSignals:") anyway,
so we really shouldn't try to obfuscate the code just to make it a bit
faster. So if optimization was the Markus' argument for making this
change I object to this change.
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [RFA] gdbserver/server.c: Replace 2x strlen() by a variable
2006-12-21 12:47 ` Mark Kettenis
@ 2006-12-21 13:04 ` Joel Brobecker
2006-12-26 15:35 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2006-12-21 13:04 UTC (permalink / raw)
To: Mark Kettenis; +Cc: Markus Deuling, GDB Patches
> > Actually, since the same string is duplicated a couple of times,
> > I would also suggest declaring a constant string "QPassSignals:"
> > and use the constant instead of risking a typo... How about:
> >
> > const char str[] = "QPassSignals:";
> >
> > and then use "sizeof (str) - 1". Is that bad coding style? Otherwise,
> > you can declare your sale constant:
> >
> > const int len = strlen (str);
> >
> > I am not reviewer, so these are just suggestions, not a request (JIC).
>
> I'm pretty sure GCC will optimize away the strlen("QPassSignals:") anyway,
> so we really shouldn't try to obfuscate the code just to make it a bit
> faster. So if optimization was the Markus' argument for making this
> change I object to this change.
How about avoiding the string duplication? Do you object to that too?
This change seems like a good idea to me - although I agree that the
risks of inconsistency are very small...
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [RFA] gdbserver/server.c: Replace 2x strlen() by a variable
2006-12-21 13:04 ` Joel Brobecker
@ 2006-12-26 15:35 ` Daniel Jacobowitz
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2006-12-26 15:35 UTC (permalink / raw)
To: Joel Brobecker; +Cc: Mark Kettenis, Markus Deuling, GDB Patches
On Thu, Dec 21, 2006 at 05:05:17PM +0400, Joel Brobecker wrote:
> > I'm pretty sure GCC will optimize away the strlen("QPassSignals:") anyway,
> > so we really shouldn't try to obfuscate the code just to make it a bit
> > faster. So if optimization was the Markus' argument for making this
> > change I object to this change.
Mark is correct, at least for recent versions of GCC. strlen of a
constant string without embedded zeros is folded to sizeof the string
minus one.
> How about avoiding the string duplication? Do you object to that too?
> This change seems like a good idea to me - although I agree that the
> risks of inconsistency are very small...
If it makes the code harder to read, I do object. This, and similar
motifs with hardcoded lengths instead of duplicated strlens, are all
through that file. I was careful to keep the duplications close
together so that they are easily visually confirmed. I don't want to
have to hunt around for the code implementing a particular packet.
If it makes the code easier to read somehow, I don't object - I'd
have to see it.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-12-26 15:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-21 7:45 [RFA] gdbserver/server.c: Replace 2x strlen() by a variable Markus Deuling
2006-12-21 11:08 ` Joel Brobecker
2006-12-21 11:48 ` Andreas Schwab
2006-12-21 12:47 ` Mark Kettenis
2006-12-21 13:04 ` Joel Brobecker
2006-12-26 15:35 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox