From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by inbox.vuxu.org (OpenSMTPD) with SMTP id 188eb01b for ; Wed, 4 Mar 2020 09:06:35 +0000 (UTC) Received: (qmail 17513 invoked by uid 550); 4 Mar 2020 09:06:33 -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 17492 invoked from network); 4 Mar 2020 09:06:32 -0000 Date: Wed, 4 Mar 2020 12:06:21 +0300 (MSK) From: Alexander Monakov To: musl@lists.openwall.com cc: =?ISO-8859-15?Q?Timo_Ter=E4s?= In-Reply-To: <20200303213348.10326-1-timo.teras@iki.fi> Message-ID: References: <20200303213348.10326-1-timo.teras@iki.fi> User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="168458499-2026930617-1583312781=:17709" Subject: Re: [musl] [PATCH] improve strerror speed This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --168458499-2026930617-1583312781=:17709 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT Hi, On Tue, 3 Mar 2020, Timo Teräs wrote: > change the current O(n) lookup to O(1) based on the machinery > described in "How To Write Shared Libraries" (Appendix B). I'm curious about the background of this change, did the inefficiency came up in practice? > --- a/src/errno/__strerror.h > +++ b/src/errno/__strerror.h > @@ -1,8 +1,9 @@ > -/* This file is sorted such that 'errors' which represent exceptional > - * conditions under which a correct program may fail come first, followed > - * by messages that indicate an incorrect program or system failure. The > - * macro E() along with double-inclusion is used to ensure that ordering > - * of the strings remains synchronized. */ > +/* The first '0' mapping will be used for error codes that > + * are not explicitly mentioned here. > + * This file is included multiple times to generate struct > + * populate it's content and create a fast lookup index to it. */ The last sentence seems to have typos ("a struct,", "its"). I would write the comment like this: /* The first entry is a catch-all for codes not enumerated here. * This file is included multiple times to declare and define a structure * with messages, and then to define a lookup table translating error codes * to offsets of corresponding fields in the structure. */ > + if (e < 0 || e >= sizeof(errmsgidx)/sizeof(errmsgidx[0])) e = 0; I think usually in musl such range checks are written in an easier-to-optimize form that tests the argument in an unsigned type, e.g. like this: if ((size_t)e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0; Thanks. Alexander --168458499-2026930617-1583312781=:17709--