zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: James Tirta Halim <tirtajames45@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH v2] prefer memcpy() over strcpy()
Date: Tue, 26 Mar 2024 01:42:16 +0100	[thread overview]
Message-ID: <36117-1711413736.217542@p2pe.Gxts.15z4> (raw)
In-Reply-To: <20240318071148.135833-1-tirtajames45@gmail.com>

On 18 Mar, James Tirta Halim wrote:
> Add zmemcpyz(), a memcpy() that nul-terminates the destination string.
> This is meant to be used when we have the strlen() of the string.

I was hoping someone else would review this. It touches on areas I'm
unsure of and I needed to check on how static inline differs between C
and C++.

> We should prefer memcpy() when we know the length because it 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.

Have you verified that this does actually have a positive effect on
performance?

If we're bothering to do this, I'd also assume that mempcpy() might also
be a teany tiny bit faster on systems that support it. Autoconf should
make that easy to check for.

> --- a/Src/zsh.h

> +#include <stddef.h>
> +#include <string.h>

Currently there are no #includes in zsh.h so I'd be uneasy about adding
some without being fully sure I understood the reasoning behind the
current setup for prototypes and headers. For now, it is only used in
string.c. It'd be easier to add there only for now and address our
use of inline functions separately. The makepro.awk mechanism largely
predates inline functions so I'm not quite sure how we can arrange for
inline functions to appear in full in string.epro or whatever zsh.mdh
includes. Anyone know?

Oliver


  reply	other threads:[~2024-03-26  0:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18  7:11 James Tirta Halim
2024-03-26  0:42 ` Oliver Kiddle [this message]
2024-03-26  2:18   ` James
2024-03-26  2:26     ` Bart Schaefer
2024-03-26  2:33       ` James

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=36117-1711413736.217542@p2pe.Gxts.15z4 \
    --to=opk@zsh.org \
    --cc=tirtajames45@gmail.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).