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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE 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 A873323A72 for ; Mon, 26 Feb 2024 01:05:06 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1708905906; b=i7Gmimr4r3nRdjZu4qqdsE2BycsQ0c2JGzE4jojny42NgXb0CNeUxAchbzrWdGcRkZ/Ck/hbHI aVtbGIL6p0fEpy7UE5lvVJyryfmruyToRdpzkQ7hxt+CQMHqOzUPJZeac7FXepfPZ74zjeTAcP xp+QAhL3w+sYLPN0YgSeB99vwTQVezlCoHaS6MFj2TGQQqB2BSJd/BL1HWjxgEIj1FSp0O8wxN 3Dxm5uCIAggmtuU1tgDvypit4Jnfu4rhfkucn7i6fS7lx22zW9tIt8cHQWQ8W4LVD7ZTZmanS3 rGad6Co3WUPxdQJXzoTsICuOi5djFzkUwTQmkuXTVJA7cA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1708905906; bh=7sLS2LWxWaHx4kwNPijkosecGeKj2M+knb3nu6qUxIE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=KZ7vtSB8b/bvJo1QPSmm44yamyyp5UEbAJdfhj/aGdh+eUf2uKBdGneRxKik3Nz776mo+FmJqI uptUQUVz5IiRZX1wgVcJZ7L2EjnZ0k2mlwBoYfd0pItZhf9oBI5ybwVJddLgkjFs6VuPOrwy9Y au7jDvaOVG5aHCt+iHiCyUmw8XNn6UizyQfP5tV/rnlXs1V9mD8XC39tWEkMfmsZaXA/xkbajz X6lglPODTOoRBv8hcg5kEwFcrKYbY9czgxg+lf4T5SYY/phrjIRsk92MrQ0dvpsApcE5iC/KtX kMq3t94mwhnz1shoF9nL/DPX4b39Sgr/hkvKMZspwa/b3g==; 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-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=mW060Vv5e4imb3THBx5U2GyaxtNjZPtPfeM7r18+kaE=; b=UjtGCteYh9MkvT1mAVJPrx/VGL 03RlvaPxD1EJLGj+vXk2VSLNgAWQYCGUj5sF9pWiqguPXoT8irbeFN7BGt00AJ9pVTgnzVxTKDtKN WjU8TaZJiC4Qo1dZmp2iQ0crwfXGumXpj77iT4PPTBbhIfzHwOUeL5omlr99K3wL3NewYleaHwJuN t3njZu4tcVaI4ey225BkQoZOesn1Tc60RShQ56nvlUADFjschWboDU4o9hUiVHYgy0vcclppWntoJ /BW9EM5DclrDKOznweKfs3siHBMNWFkSX1iILPyNNDh4Az/ZrAOc9X839ksvbhOibiix3NQ04TdYz 1qQEDnfA==; Received: by zero.zsh.org with local id 1reOUR-000EkB-Q8; Mon, 26 Feb 2024 00:05:03 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f48.google.com ([209.85.208.48]:49374) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1reOUA-000EQX-FH; Mon, 26 Feb 2024 00:04:47 +0000 Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5649c25369aso3082490a12.2 for ; Sun, 25 Feb 2024 16:04:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1708905886; x=1709510686; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mW060Vv5e4imb3THBx5U2GyaxtNjZPtPfeM7r18+kaE=; b=O2svKkCeGMC47YptAAMXocBCIuivHtW9PL+a5HARphvF0M1SRJSIGqOH4n7EdPDMDr YO/fbQp7HspwRhbnMmG9eBga1x/OYhnGqEFU6G5Fu3jb2rpGCxkCRHFvv22vop+WlWCn OxrwbnldRTeIbNrWyc9hgx/wbPC5cCpWxpqHBEMu4z/+w3X3u4Zlx+iwVm6C4TuxkFFd xKCfGL5ZswYyK19d1dnJ2TYQLW8+aLZpxotTXGX/Nyu152vAHDKuw0Wy7hDgGfMK6RnW P+N0qMa2XB3N2mnF6UIXQ42bSNodSA8eHc3/j5UapFySqCqdHRFUCdCv9cLr682NvubA 9pTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708905886; x=1709510686; h=content-transfer-encoding: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=mW060Vv5e4imb3THBx5U2GyaxtNjZPtPfeM7r18+kaE=; b=gsx4XTmHP5ElXUKYK1ryJZt8XahuG56qdo4V4PDjKXHO3URXRXV88HXHNxF6h96doG N27Z0U/WJTS7SSWBAMQ/VMfXyntVLnhc4F6lYqmX3ER+58EkU2fP6+spQ+BvFqdTtvC4 u6D9a/0xUVA5GnSr1Ora5ZX7vMf63zTBzgiVc9QwNCvoukAvWZCFC/invqmAowiILgxN i792DRUlgYyjxJvwq7bGum1Dnax5UoIeAZ0jy0nwymnZOEMt0q66J9SOHXT5PeK19+jW f7UJ4HXtPIukmmR5/JLgeuWMtOpyl9pWagaakK6/HKLAIF/34WfN98cmN9c2kEGbXkC9 k+4w== X-Gm-Message-State: AOJu0Yx3vXQgjQw4bz8uOUcFFOJ+pMVE0GM3zB8/YQiHns4HGGnsx/hX 75o4W+aSI58Qsy64sj1wuHnmREVfZTCnx4eF6Z5E/RVhggnPk7/K9A9FKyvFU+2YwbsJactKw39 gH0r8Fe3bRNOH2E2sEpdaMh9RNOW4ozgTBYBPVch37BlT0zs= X-Google-Smtp-Source: AGHT+IGpqUS13d9cYI2FlsyR/lHC3QCnJxmp/n3UiSZVXbv3wXxmf2mzNE2twYezAEiG2mgrMF1wJ6uy4x+66upYYHE= X-Received: by 2002:a17:906:d96c:b0:a43:4ddb:a9cd with SMTP id rp12-20020a170906d96c00b00a434ddba9cdmr802847ejb.37.1708905885809; Sun, 25 Feb 2024 16:04:45 -0800 (PST) MIME-Version: 1.0 References: <20240224144041.7huny3lmihsrokdm@chazelas.org> <20240225065400.wrb3jxr7vub6t42v@chazelas.org> In-Reply-To: <20240225065400.wrb3jxr7vub6t42v@chazelas.org> From: Bart Schaefer Date: Sun, 25 Feb 2024 16:04:34 -0800 Message-ID: Subject: Re: Example / partial fix for printf with math expressions To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52614 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 Sat, Feb 24, 2024 at 10:54=E2=80=AFPM Stephane Chazelas wrote: > > 2024-02-24 14:40:41 +0000, Stephane Chazelas: > [...] > > + zlongval =3D (curarg) ? mathevali(metafy(curarg, = curlen, META_HEAPDUP)) : 0; > > That incur a performance penalty: > > The numbers end up being metafied (earlier), unmetafied by > printf, metafied again by printf here and that metafication > processed by the math handler I guess. The reason this went unobserved for so long is that metafication only matters to a couple of things in math: 1) proper handling of parameter references, like your a[x]++ example 2) those pesky error messages that started this whole thread As far as I can tell there are no other circumstances in which metafication is necessary for the syntax of math expressions. > Maybe the performance could be *improved* instead if the > unmetafication could be skipped altogether in printf in those > cases? That's certainly possible, but it would mean that every branch of the big "case" statements for %-replacement would have to do their own unmetafy(), rather than a single loop at the top covering the entire argv array. The -s/-S/-z options also reverse the unmetafy(), so some heavy refactoring of bin_print() is needed to unroll this completely. However, I think you could change META_HEAPDUP and META_USEHEAP to META_NOALLOC, becuase you're re-metafying back into the same space that was originally unmetafied? That might cut the performance penalty a lot.