Skip to content

compressed errno strings#713

Merged
adriweb merged 1 commit intomasterfrom
opt_errno_string
Feb 27, 2026
Merged

compressed errno strings#713
adriweb merged 1 commit intomasterfrom
opt_errno_string

Conversation

@ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Feb 25, 2026

Compressed the errno strings used for strerror/perror. The lookup table is 79 * 3 = 237 bytes smaller, at the cost of 28 bytes of code, yielding a net savings of 209 bytes.

The downside is that retrieving the errno strings is now O(N) instead of O(1). However, the worst case retrieval time is ~0.8 milliseconds. (31ms to effectively do for (int i = 0; i < 79; i++) { strerror(i); })

// 3 bytes of overhead to store pointers to each string
static char const * const errno_strings[] = {
    "no error",
    "EPERM",
    "EINVAL",
    "EIO",
    "EDOM",
    "ERANGE",
    "EILSEQ",
};
// no overhead
static constexpr char errno_strings[] = {
    "no error"
    "\0EPERM"
    "\0EINVAL"
    "\0EIO"
    "\0EDOM"
    "\0ERANGE"
    "\0EILSEQ"
};

@adriweb adriweb merged commit d9ad631 into master Feb 27, 2026
9 checks passed
@adriweb adriweb deleted the opt_errno_string branch February 27, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants