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

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

On Tue, Mar 26, 2024, 7:42 AM Oliver Kiddle <opk@zsh.org> wrote:

> 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?

Musl doesn't provide an assembly implementation for strcpy, so it should be
as fast as asm memcpy is to C memcpy. Glibc does, so performance difference
is theoretical.

> 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.
>
Sure.

> > --- 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?
>
I think it would be better to make it a macro for now. The function call
overhead may become a pessimization for small strings.

> Oliver
>

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

  reply	other threads:[~2024-03-26  2:19 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
2024-03-26  2:18   ` James [this message]
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=CANDqPp35KYKZT7QkNjyVfoEtwG7gn8bJDQHfcRSfTCD6nea58g@mail.gmail.com \
    --to=tirtajames45@gmail.com \
    --cc=opk@zsh.org \
    --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).