Systemd/src/basic/arphrd-list.c
Zbigniew Jędrzejewski-Szmek 7e833f301e basic: massively reduce the size of arphdr lookup functions
Our biggest object in libsystemd was a table full of zeros, for the arphdr
names. Let's use a switch (which gcc nicely optimizes for us), instead a
table with a gap between 826 and 65534:

$ ls -l build{,2}/src/basic/a6ba3eb@@basic@sta/arphrd-list.c.o
-rw-rw-r--. 1 zbyszek zbyszek 540232 Sep 22 00:29 build/src/basic/a6ba3eb\@\@basic\@sta/arphrd-list.c.o
-rw-rw-r--. 1 zbyszek zbyszek  20512 Sep 25 11:56 build2/src/basic/a6ba3eb\@\@basic\@sta/arphrd-list.c.o

$ ls -l build{,2}/src/shared/libsystemd-shared-243.so
-rwxrwxr-x. 1 zbyszek zbyszek 6774368 Sep 22 00:29 build/src/shared/libsystemd-shared-243.so
-rwxrwxr-x. 1 zbyszek zbyszek 6254808 Sep 25 12:16 build2/src/shared/libsystemd-shared-243.so

No functional change.
2019-09-25 12:17:22 +02:00

26 lines
542 B
C

/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
#include <linux/if_arp.h>
#include <string.h>
#include "arphrd-list.h"
#include "macro.h"
static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
#include "arphrd-from-name.h"
#include "arphrd-to-name.h"
int arphrd_from_name(const char *name) {
const struct arphrd_name *sc;
assert(name);
sc = lookup_arphrd(name, strlen(name));
if (!sc)
return -EINVAL;
return sc->id;
}