zsh-workers
 help / color / mirror / code / Atom feed
From: James <tirtajames45@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH v2] string.c: remove use of strcat() after strlen()
Date: Sun, 31 Dec 2023 12:10:20 +0700	[thread overview]
Message-ID: <CANDqPp1yQ_r_6QSGp27mw7_5Nhc-XHowbe-TyOqnU8jb1KLDzg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7a9xTJLPgagPmHE15Jy1vXDmDKKmuUi-JUYSqivnc-q8A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 862 bytes --]

Since we are already calling strlen() beforehand to know the size of
allocation, we can just memcpy() from BASE + BASE_LEN and avoid another
strlen() call in strcat(). We should prefer memcpy() because we always know
the length and most libc implementations provide an assembly implementation
of memcpy but maybe not strcpy(). Even if it is implemented in assembly,
memcpy() is likely to be faster than strcpy() since as the loop condition
strcpy() needs to check for zeros in SRC, whereas memcpy() can just
decrement the size.

I'm using a MEMPCPY macro because I don't know how zsh handles using
GNU/POSIX extensions.

On Sun, Dec 31, 2023 at 11:22 AM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> I take it this is intended to be an optimization?
>
> Please do provide some background / rationale when sending a patch.
> Thanks.
>

[-- Attachment #2: Type: text/html, Size: 1150 bytes --]

  reply	other threads:[~2023-12-31  5:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-26  6:01 James Tirta Halim
2023-12-31  4:22 ` Bart Schaefer
2023-12-31  5:10   ` James [this message]
2023-12-31  5:20     ` Bart Schaefer
2024-01-28  0:57     ` Oliver Kiddle

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=CANDqPp1yQ_r_6QSGp27mw7_5Nhc-XHowbe-TyOqnU8jb1KLDzg@mail.gmail.com \
    --to=tirtajames45@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).