mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: musl@lists.openwall.com
Cc: "Timo Teräs" <timo.teras@iki.fi>
Subject: Re: [musl] [PATCH] improve strerror speed
Date: Wed, 4 Mar 2020 12:06:21 +0300 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.20.13.2003041151460.17709@monopod.intra.ispras.ru> (raw)
In-Reply-To: <20200303213348.10326-1-timo.teras@iki.fi>

[-- Attachment #1: Type: text/plain, Size: 1596 bytes --]

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

  reply	other threads:[~2020-03-04  9:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 21:33 Timo Teräs
2020-03-04  9:06 ` Alexander Monakov [this message]
2020-03-04  9:17   ` Timo Teras
2020-03-04  9:27   ` [musl] [PATCH v2] " Timo Teräs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.20.13.2003041151460.17709@monopod.intra.ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=musl@lists.openwall.com \
    --cc=timo.teras@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).