From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8135 invoked from network); 31 Dec 2023 05:11:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Dec 2023 05:11:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1703999468; b=TfCzaqHf2hemm8ltaujC1VhLdHp5q2cn+C+o7DYpPKbznI1gXHdV3gaXj+bAEjNpL/hIzWKp81 Fwug03k5sBDYTfYsNSvobfjBf5k8dCFMu2uPY2exURsHY5nfQxzivreB1LAoGM8X9IbQxwWpmw iNZzieje95R/safjBzKJaVd694MrWXUSvwkGhH835sPdY9OS5fFBPWpd9JzwViPZ2ajojK5NV1 hiSnThv16uvqkD8CAxZS8kwNsDykkq6VZJNXZqxVlQmqMhzQ4ICMS3as7z7WS5sW4pdA3UfCW3 hNuux4EJO5ZgdFQJibzNG0cj8DUui4BJh1/LIa2fyzOIwA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f42.google.com) smtp.remote-ip=209.85.128.42; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1703999468; bh=aNSAZqU8VyfbaFA29UqqX4gf8/wI4/QlLoFj3lSUN/g=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=a8W675O1ERtQh8FhgAuHkt9ubFajRD/MskxOULFaz31wxbvgor1ri0FPC0UQIbXvaUMvqbs9Rs 0c73Enwe7izgfmUCrdT2aZ7OzaHIU0OEzjbCZczM8OmcevPq2etJQrmblgmT9OefRdz0xOKNri AAru3jY6xST+satZWlXRDNOGfquoUsC3iK28XhHnI/9O23Jg/+T0sVVaEQZ+b1OLf2W3dZlkmG HEJdhmn8REKeyKrtQ2fGTxlUg5T5ACmP6VypBXbJH85DshlGJJ03shgiwSJcay2DblN7FM7Cbm 4VmKvCElHE0HZspeUWHPDKzyPVp11SRcfyf42FhJQ66AZg==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=aNSAZqU8VyfbaFA29UqqX4gf8/wI4/QlLoFj3lSUN/g=; b=hyLp5o8v2td8y5lq+L6UEiqtuf YyzMI/uS0w3hf/Qgi1SJFt4J3b9+7jlTU370NyTEOiGDz/T+nTGCKlzssjhq4/zHU2CyilkW1aXKV xUZzMHAxi7UgiIh0hW800gR26be+uSE+sEQS/jc5MGh8MwHe4HdiLBTmaEsDW2Z/AHS6DioUFOMFO 1y9oT+5UNW7vWDYbwMoqQrenBxP0+f+nCLBrONdEaIQuxHEog7+UqexHFwG+tCsE/ukWENZCR/rd0 Ifot8MKu/lHxjetWCV4lTIxxANSJuEwJdH0AcL4kuN/bNQP02v7S/sM0vxmORTz76EK9m9943Shcs tFpmoSiQ==; Received: by zero.zsh.org with local id 1rJo6N-0008wc-Bm; Sun, 31 Dec 2023 05:11:07 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f42.google.com) smtp.remote-ip=209.85.128.42; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f42.google.com ([209.85.128.42]:49281) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rJo5o-0008bT-OQ; Sun, 31 Dec 2023 05:10:33 +0000 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40d5b159350so39458265e9.2 for ; Sat, 30 Dec 2023 21:10:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703999432; x=1704604232; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=aNSAZqU8VyfbaFA29UqqX4gf8/wI4/QlLoFj3lSUN/g=; b=amzQUygVJkn8gLEXg+cvC2FyoI/FAicXjvS+5L1+pvSh6GxDv6rbH95VJCm3esn33z jCjok6WPg0z8PV5R0xCUaFa4hxZxqGv5J1Up+HiMgD10PL/amxGzwp7Q3ATbCbHMit+Z DU0Qq+BMfxOx0zMuEJNBsbQWVXdLBPOh2AQBPkwcbD1EThqynfknc7UYo6z6PD6aIHzv 4jsK8KUmQJKuDEa5B+qHk+Tb+sBRtCH4lJoR+fTJkAahb+hgPlWDVNYeHsqgkpcwu3td k/ouL4ilscphskZCRMZC7DnwYdyFAj0lGL13yrPGVdRTCBvfQlv0ugU6QSxBIo1jNB3K /Bvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703999432; x=1704604232; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aNSAZqU8VyfbaFA29UqqX4gf8/wI4/QlLoFj3lSUN/g=; b=Zrb+oVoDd8nbFztSyC/MZTRBtFssBQxS6kKvYzltliW9C4za+ubdA4MmAqfyNQ+AsT wYFfPVDYv1hp0qTXYSyUOwvpfdwt7MbBHNJTALJYY9vkCAQltt8rG44bBO83c2Rkeitp E1Y5KcblulSgZUQMcNBT+8Hqe8c/bnQWtY+CiL+EWGFVm7e4yMffuxDNmNIBgzbcbSW2 L19U9Z6xUsScNP+RO8nX6XX+X6au9rT32XaRYrPdhAk+ZFzKlGf4ASxYuGTy4jHZ9aN0 dWffQom3Z3epNZRGBEGN/StcoIy7t5dEYiwlTEKotCkCuRssZLjGsrRN6B8gc4nPUO/l qKlQ== X-Gm-Message-State: AOJu0YyfOZCGi4T3cZFDkVzpAcGibUK5TzjASA/0OmM+yrcSpfkfPXwy IkkgOR5t/lZty1TWfZlC0WjdbiLHjVcgaUV8JxyrfDIxY04= X-Google-Smtp-Source: AGHT+IHLHQCtDfa8zTvouZ6V53K86sm6fmSTXhIYREbhRMMNUEpAOy5At1fpi7gCPZy2d2l2JVr0wee6XUnTTp9o2h4= X-Received: by 2002:a05:600c:1c1e:b0:40d:6051:8d0c with SMTP id j30-20020a05600c1c1e00b0040d60518d0cmr2654886wms.6.1703999431799; Sat, 30 Dec 2023 21:10:31 -0800 (PST) MIME-Version: 1.0 References: <20231226060159.182340-1-tirtajames45@gmail.com> In-Reply-To: From: James Date: Sun, 31 Dec 2023 12:10:20 +0700 Message-ID: Subject: Re: [PATCH v2] string.c: remove use of strcat() after strlen() To: Bart Schaefer Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="000000000000d4767b060dc7482f" X-Seq: 52434 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: --000000000000d4767b060dc7482f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFAM Bart Schaefer wrote: > I take it this is intended to be an optimization? > > Please do provide some background / rationale when sending a patch. > Thanks. > --000000000000d4767b060dc7482f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Since we are already calling strlen() beforehand to know t= he size of allocation, we can just memcpy() from BASE=C2=A0+ BASE_LEN and a= void another strlen() call in strcat(). We should prefer memcpy() because w= e 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 loo= p 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=E2=80=AFAM Bart Schaefer <schaefer@brasslantern.com> wrote:
I take it this is intended to be an optim= ization?

Please do provide some background / rationale when sending a patch.=C2=A0 T= hanks.
--000000000000d4767b060dc7482f--