From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 8857A2284C for ; Tue, 26 Mar 2024 01:42:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=dl06ssAE5XCepyLeNpz3NBVPCPCPjedj7REM1prXknU=; b=koHgLw3OEvtLR+DlZqjcddK2oV mwUu3IFlApVB3GS7/bS3HeEym3ciMADeUK24K/6GYZsTcjjrE7n4nwyepV3wMdeMZCoahF44jCYVk IE4hjQkvDxPVUE6KzdcxUfFwIT2wYTwUX3X+x9QniBpQE7xd77kpSrAoTufPZgxzKqRmeqtahtHqy uc6Rj8EyKZ4JaNvKBK1YFGzJBkCgwLyeuHeTAk1GBRkUTZO/k5VTceEhoiLTQUIJ81B63SKeT6zk1 nyFIU/YGE7/c1oGTNiRa3bzqykDaOcQXL6BwjJAomgicwqMuh01n7W4G5cqtvOpwVUJZ5SSF4aKfZ DydSFYCA==; Received: by zero.zsh.org with local id 1route-000DPJ-S6; Tue, 26 Mar 2024 00:42:34 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1routM-000D4h-Kx; Tue, 26 Mar 2024 00:42:16 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1routM-000000009OY-0vSo; Tue, 26 Mar 2024 01:42:16 +0100 cc: zsh-workers@zsh.org In-reply-to: <20240318071148.135833-1-tirtajames45@gmail.com> From: Oliver Kiddle References: <20240318071148.135833-1-tirtajames45@gmail.com> To: James Tirta Halim Subject: Re: [PATCH v2] prefer memcpy() over strcpy() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <36116.1711413736.1@hydra> Date: Tue, 26 Mar 2024 01:42:16 +0100 Message-ID: <36117-1711413736.217542@p2pe.Gxts.15z4> X-Seq: 52820 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 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 > +#include 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