From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/6] string: reduce strjoin runtime, drop trailing separator
Date: Thu, 27 Oct 2022 09:33:34 +0200 [thread overview]
Message-ID: <20221027073334.GS6702@pengutronix.de> (raw)
In-Reply-To: <dc48c8c4-517c-349f-8582-1a718b4d699f@pengutronix.de>
On Thu, Oct 27, 2022 at 09:24:20AM +0200, Ahmad Fatoum wrote:
> Hi,
>
> On 27.10.22 08:56, Sascha Hauer wrote:
> > On Wed, Oct 26, 2022 at 08:42:02AM +0200, Ahmad Fatoum wrote:
> >> The implementation of strjoin is a bit suboptimal. The destination
> >> string is traversed from the beginning due to strcat and we have a
> >> left-over separator at the end, while it should only be in-between.
> >>
> >> Fix this.
> >
> > Rather than fixing a just introduced function I would expect a patch
> > introducing strjoin() and then another one converting the time command
> > over to use it.
>
> What difference does it make?
You wouldn't have to fixup code you just introduced.
> >
> > for (i = 0; i < arrlen; i++) {
> > p = stpcpy(p, arr[i]);
> > if (i < arrlen - 1)
> > p = stpcpy(p, separator);
> > }
> >
> > That would also allow you to optimize the allocated buffer size above.
>
> I like my version more. I dislike these once-only checks inside loops.
No problem ;)
for (i = 0; i < arrlen - 1; i++) {
p = stpcpy(p, arr[i]);
p = stpcpy(p, separator);
}
stpcpy(p, arr[i]);
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2022-10-27 7:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 6:42 [PATCH 1/6] commands: add new uptime command Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 2/6] commands: time: refactor into new strjoin Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 3/6] string: reduce strjoin runtime, drop trailing separator Ahmad Fatoum
2022-10-27 6:56 ` Sascha Hauer
2022-10-27 7:24 ` Ahmad Fatoum
2022-10-27 7:33 ` Sascha Hauer [this message]
2022-10-27 7:53 ` Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 4/6] test: self: add strjoin tests Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 5/6] commands: drvinfo: support filtering by driver Ahmad Fatoum
2022-10-27 7:29 ` Sascha Hauer
2022-10-27 7:51 ` Ahmad Fatoum
2022-10-27 8:49 ` Sascha Hauer
2022-10-26 6:42 ` [PATCH 6/6] test: self: only include ramfs selftest when CONFIG_SELFTEST_FS_RAMFS=y Ahmad Fatoum
2022-10-27 7:11 ` [PATCH 1/6] commands: add new uptime command Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221027073334.GS6702@pengutronix.de \
--to=sha@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox