All of lore.kernel.org
 help / color / mirror / Atom feed
* [Q] Cleaning string whitespace trimming. Does it make any sense?
@ 2012-06-12 17:52 Ezequiel Garcia
  2012-06-12 18:49 ` Dan Carpenter
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2012-06-12 17:52 UTC (permalink / raw)
  To: kernel-janitors

Hi Dan,

If you grep "isspace" through the code you will find lots of places
using, most of them
for removing leading and/or whitespace from a string.

Examples:

* sound/usb/card.c -> has a function of its own
http://tomoyo.sourceforge.jp/cgi-bin/lxr/ident?i=remove_trailing_spaces
* sound/pci/hda/hda_hwdep.c -> also! has a function of its own
http://tomoyo.sourceforge.jp/cgi-bin/lxr/ident?i=remove_trail_spaces
* drivers/char/ipmi/ipmi_si_intf.c -> embeds a custom algorithm ->
http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/drivers/char/ipmi/ipmi_si_intf.c#L1690

As we have a special function for this (or could create in case there
isn't one already)
I wonder if it makes any sense to do some patches for this, since it
won't fix anything
and it's just to improve readability.

What do you think?

Thanks,
Ezequiel.

PD: Am I too pretty-code paranoid?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
@ 2012-06-12 18:49 ` Dan Carpenter
  2012-06-12 20:58 ` Dan Carpenter
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2012-06-12 18:49 UTC (permalink / raw)
  To: kernel-janitors

We already have strim() which removes leading and trailing
whitespace.  But sure, that sounds like a good idea.  It would go in
front of strim() and strim would call it first then strim() would
look like this:

char *strim(char *s)
{
	trim_trailing(s);
	return skip_spaces(s);
}

Good luck on getting everyone to agree on a name for your function.
Python uses rstrip() for this.  CC Andrew Morton and lkml when you
have a patch ready.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
  2012-06-12 18:49 ` Dan Carpenter
@ 2012-06-12 20:58 ` Dan Carpenter
  2012-06-12 22:03 ` Ezequiel Garcia
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2012-06-12 20:58 UTC (permalink / raw)
  To: kernel-janitors

Actually, on second thought strim() already does what we want.  Just
ignore the return value.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
  2012-06-12 18:49 ` Dan Carpenter
  2012-06-12 20:58 ` Dan Carpenter
@ 2012-06-12 22:03 ` Ezequiel Garcia
  2012-06-13  6:06 ` Dan Carpenter
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2012-06-12 22:03 UTC (permalink / raw)
  To: kernel-janitors

On Tue, Jun 12, 2012 at 5:58 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> Actually, on second thought strim() already does what we want.  Just
> ignore the return value.
>

But it could make sense to fix such redundant code?

I'm unsure what git tree should I base the patches, given
I'd be touching all over the place. Perhaps linux-next?

Thanks,
Ezequiel.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (2 preceding siblings ...)
  2012-06-12 22:03 ` Ezequiel Garcia
@ 2012-06-13  6:06 ` Dan Carpenter
  2012-06-13  7:23 ` walter harms
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2012-06-13  6:06 UTC (permalink / raw)
  To: kernel-janitors

On Tue, Jun 12, 2012 at 07:03:04PM -0300, Ezequiel Garcia wrote:
> On Tue, Jun 12, 2012 at 5:58 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > Actually, on second thought strim() already does what we want.  Just
> > ignore the return value.
> >
> 
> But it could make sense to fix such redundant code?
> 

Yep.

> I'm unsure what git tree should I base the patches, given
> I'd be touching all over the place. Perhaps linux-next?

Yep.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (3 preceding siblings ...)
  2012-06-13  6:06 ` Dan Carpenter
@ 2012-06-13  7:23 ` walter harms
  2012-06-13 17:06 ` Ezequiel Garcia
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: walter harms @ 2012-06-13  7:23 UTC (permalink / raw)
  To: kernel-janitors



Am 13.06.2012 00:03, schrieb Ezequiel Garcia:
> On Tue, Jun 12, 2012 at 5:58 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>> Actually, on second thought strim() already does what we want.  Just
>> ignore the return value.
>>
> 
> But it could make sense to fix such redundant code?
> 
> I'm unsure what git tree should I base the patches, given
> I'd be touching all over the place. Perhaps linux-next?
> 

Hi Ezequiel,
as rule-of-the-thumb: just do it.

Convenience functions like trim() are added add irregular intervals because
they appear only if someone spots a pattern that he things is worth the effort.
Older Code does not know about it, so changes are required through the whole
code (look at patches from Julia Lawall, she has developed a tool to spot pattern).

How does it look from a maintainers perspective ?
1. He can remove a function from your code and reduce what you have to maintain -> good
2. He has a special need and need its own code -> but at least you know about it now :)

in short: you can make nothing wrong

re,
 wh

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (4 preceding siblings ...)
  2012-06-13  7:23 ` walter harms
@ 2012-06-13 17:06 ` Ezequiel Garcia
  2012-06-13 18:16 ` Ezequiel Garcia
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2012-06-13 17:06 UTC (permalink / raw)
  To: kernel-janitors

On Wed, Jun 13, 2012 at 4:23 AM, walter harms <wharms@bfs.de> wrote:
Hi Walter,

>
> as rule-of-the-thumb: just do it.

Thanks for this advice. I'm gonna do just that.

>
> Convenience functions like trim() are added add irregular intervals because
> they appear only if someone spots a pattern that he things is worth the effort.
> Older Code does not know about it, so changes are required through the whole
> code (look at patches from Julia Lawall, she has developed a tool to spot pattern).
>
> How does it look from a maintainers perspective ?
> 1. He can remove a function from your code and reduce what you have to maintain -> good
> 2. He has a special need and need its own code -> but at least you know about it now :)
>
> in short: you can make nothing wrong

Okey, thanks again.

Regards,
Ezequiel.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (5 preceding siblings ...)
  2012-06-13 17:06 ` Ezequiel Garcia
@ 2012-06-13 18:16 ` Ezequiel Garcia
  2012-06-13 18:21 ` Dan Carpenter
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2012-06-13 18:16 UTC (permalink / raw)
  To: kernel-janitors

Dan,

On Tue, Jun 12, 2012 at 5:58 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> Actually, on second thought strim() already does what we want.  Just
> ignore the return value.
>

If I *only* want to remove trailing whitespace, using strim() does the job
but it *also* tries to remove leading whitespace.

That can't hurt, but it also doesn't hurt to add a separate function
for that, right?

Thanks,
Ezequiel.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (6 preceding siblings ...)
  2012-06-13 18:16 ` Ezequiel Garcia
@ 2012-06-13 18:21 ` Dan Carpenter
  2012-06-13 18:30 ` Ezequiel Garcia
  2012-06-13 18:37 ` Dan Carpenter
  9 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2012-06-13 18:21 UTC (permalink / raw)
  To: kernel-janitors

On Wed, Jun 13, 2012 at 03:16:24PM -0300, Ezequiel Garcia wrote:
> Dan,
> 
> On Tue, Jun 12, 2012 at 5:58 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > Actually, on second thought strim() already does what we want.  Just
> > ignore the return value.
> >
> 
> If I *only* want to remove trailing whitespace, using strim() does the job
> but it *also* tries to remove leading whitespace.
> 
> That can't hurt, but it also doesn't hurt to add a separate function
> for that, right?

It returns a pointer to the first non whitespace character, but you
can just ignore the return value.  Normally the first character is
going to be non whitespace, so it's not even a slow down.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (7 preceding siblings ...)
  2012-06-13 18:21 ` Dan Carpenter
@ 2012-06-13 18:30 ` Ezequiel Garcia
  2012-06-13 18:37 ` Dan Carpenter
  9 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2012-06-13 18:30 UTC (permalink / raw)
  To: kernel-janitors

On Wed, Jun 13, 2012 at 3:21 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> It returns a pointer to the first non whitespace character, but you
> can just ignore the return value.  Normally the first character is
> going to be non whitespace, so it's not even a slow down.
>

Got it. I guess when you say there is no performance impact,
it's because this kind of functionality is used very sparsely in the code.
(Please correct me if I'm wrong.)

Thanks,
Ezequiel.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Cleaning string whitespace trimming. Does it make any sense?
  2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
                   ` (8 preceding siblings ...)
  2012-06-13 18:30 ` Ezequiel Garcia
@ 2012-06-13 18:37 ` Dan Carpenter
  9 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2012-06-13 18:37 UTC (permalink / raw)
  To: kernel-janitors

On Wed, Jun 13, 2012 at 03:30:57PM -0300, Ezequiel Garcia wrote:
> On Wed, Jun 13, 2012 at 3:21 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > It returns a pointer to the first non whitespace character, but you
> > can just ignore the return value.  Normally the first character is
> > going to be non whitespace, so it's not even a slow down.
> >
> 
> Got it. I guess when you say there is no performance impact,
> it's because this kind of functionality is used very sparsely in the code.
> (Please correct me if I'm wrong.)

If the first character is non-white space then it's just one extra
branch statement.  And yeah, this tends to not be fast path code is
my guess.

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-06-13 18:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-12 17:52 [Q] Cleaning string whitespace trimming. Does it make any sense? Ezequiel Garcia
2012-06-12 18:49 ` Dan Carpenter
2012-06-12 20:58 ` Dan Carpenter
2012-06-12 22:03 ` Ezequiel Garcia
2012-06-13  6:06 ` Dan Carpenter
2012-06-13  7:23 ` walter harms
2012-06-13 17:06 ` Ezequiel Garcia
2012-06-13 18:16 ` Ezequiel Garcia
2012-06-13 18:21 ` Dan Carpenter
2012-06-13 18:30 ` Ezequiel Garcia
2012-06-13 18:37 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.