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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20980 invoked from network); 15 May 2023 08:32:20 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 15 May 2023 08:32:20 -0000 Received: (qmail 11807 invoked by uid 550); 15 May 2023 08:32:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11772 invoked from network); 15 May 2023 08:32:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fifth.space; s=20190812; t=1684139520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kP2BoVq3kHrR2DZ0Y8PeJAm5sWITtFKLKpGR9kkj/gU=; b=l12zOVrVAQw/fdNB++AwtfHt8L46EWYLFufYCUIOIxrBBF5mb4kKi6FLMFxLxwdXH5YvzP Tns43iC0wERuTOVt4gBRrj+Bxzlm5SynusK2EUjDK7mTuA3F0THyEa0TX2pzbBYjh7pwOW Eqy0gr4IS/oIyegPTc0i72MqlZfXz4bkW4zoVMgbxI7oiTdYXHXH9zb13nNhNqLysd3kTW Wd2czQMC9fyVbjQYvEmps6e3XGafUZXFQsHD3N/xSEOmf6gl+l1gGf4+wiLTqL3znGbf4l VtYWV8qxdlkxpgi1ZfHkmmCxdIJQcsRfhlUTmIu+/N1sSPBdAOoBx6APCqWiFw== Date: Mon, 15 May 2023 10:31:38 +0200 From: Quentin Rameau To: musl@lists.openwall.com Message-ID: <20230515103138.07f4c02e.quinq@fifth.space> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] [Patch 1/1] vfprintf: optimize vfprintf performance Hi 847567161 > I made a patch to get nl_arg when we see '$' ranther than visit the = format anyway=EF=BC=8Ccould you please help me review it=EF=BC=9F >=20 > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c old mode 100644 = new mode 100755 index 9b961e7f..3294e23b --- a/src/stdio/vfprintf.c +++ b/s= rc/stdio/vfprintf.c @@ -427,7 +427,7 @@ static int getint(char **s) { ret= urn i; } -static int printf_core(FILE *f, const char *fmt, va_list *ap, = union arg *nl_arg, int *nl_type) +static int printf_core(FILE *f, const cha= r *fmt, va_list *ap, union arg *nl_arg, int *nl_type, union arg* nl_arg_ptr= ) { char *a, *z, *s=3D(char *)fmt; unsigned l10n=3D0, fl; @@ -462,6 +4= 62,12 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, unio= n arg *nl_arg, if (l) continue; if (isdigit(s[1]) && s[2]= =3D=3D'$') { + if (nl_arg_ptr =3D=3D NULL) { + nl_arg_ptr =3D nl_arg; = + if (printf_core(0, fmt, ap, nl_arg, nl_type, nl_arg_ptr) < 0) { + = return -1; + } + } l10n=3D1; argpos =3D s[1]-'0'; s+=3D3; = @@ -477,6 +483,12 @@ static int printf_core(FILE *f, const char *fmt, va_li= st *ap, union arg *nl_arg, /* Read field width */ if (*s=3D=3D'*') { = if (isdigit(s[1]) && s[2]=3D=3D'$') { + if (nl_arg_ptr =3D= =3D NULL) { + nl_arg_ptr =3D nl_arg; + if (printf_core(0, fmt, ap, = nl_arg, nl_type, nl_arg_ptr) < 0) { + return -1; + } + } l= 10n=3D1; nl_type[s[1]-'0'] =3D INT; w =3D nl_arg[s[1]-'0'].i; @@ = -491,6 +503,12 @@ static int printf_core(FILE *f, const char *fmt, va_list = *ap, union arg *nl_arg, /* Read precision */ if (*s=3D=3D'.' &&am= p; s[1]=3D=3D'*') { if (isdigit(s[2]) && s[3]=3D=3D'$') { + = if (nl_arg_ptr =3D=3D NULL) { + nl_arg_ptr =3D nl_arg; + if (printf= _core(0, fmt, ap, nl_arg, nl_type, nl_arg_ptr) < 0) { + return -1; + = } + } nl_type[s[2]-'0'] =3D INT; p =3D nl_arg[s[2]-'0'].i; = s+=3D4; @@ -659,16 +677,13 @@ int vfprintf(FILE *restrict f, const cha= r *restrict fmt, va_list ap) va_list ap2; int nl_type[NL_ARGMAX+1] =3D = {0}; union arg nl_arg[NL_ARGMAX+1]; + union arg* nl_arg_ptr =3D NULL; u= nsigned char internal_buf[80], *saved_buf =3D 0; int olderr; int ret; = /* the copy allows passing va_list* even if va_list is an array */ va_= copy(ap2, ap); - if (printf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { = - va_end(ap2); - return -1; - } FLOCK(f); olderr =3D f->flags &a= mp; F_ERR; @@ -680,7 +695,7 @@ int vfprintf(FILE *restrict f, const char *r= estrict fmt, va_list ap) f->wpos =3D f->wbase =3D f->wend =3D 0= ; } if (!f->wend && __towrite(f)) ret =3D -1; - else ret =3D= printf_core(f, fmt, &ap2, nl_arg, nl_type); + else ret =3D printf_core= (f, fmt, &ap2, nl_arg, nl_type, nl_arg_ptr); if (saved_buf) { f-&g= t;write(f, 0, 0); if (!f->wpos) ret =3D -1; Could you try sending it in a more readable way? One way would be to commit the diff and sending it with git-send-email but attaching a diff file, or simply inlining the patch as plain-text would also work. Thank you!