From: Ahmad Fatoum <a.fatoum@pengutronix.de> To: Sascha Hauer <sha@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:53:34 +0200 [thread overview] Message-ID: <bf2873ae-7bf0-0b2a-abb1-e824144d8b81@pengutronix.de> (raw) In-Reply-To: <20221027073334.GS6702@pengutronix.de> On 27.10.22 09:33, Sascha Hauer wrote: > 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. The alternative of changing stuff just to shift it around directly after doesn't sound that much more appealing, but I can do that anyway. > >>> >>> 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]); I can do that, albeit with mempcpy. I already got separatorlen. Cheers, Ahmad > > 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:54 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 2022-10-27 7:53 ` Ahmad Fatoum [this message] 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=bf2873ae-7bf0-0b2a-abb1-e824144d8b81@pengutronix.de \ --to=a.fatoum@pengutronix.de \ --cc=barebox@lists.infradead.org \ --cc=sha@pengutronix.de \ --subject='Re: [PATCH 3/6] string: reduce strjoin runtime, drop trailing separator' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox