summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorBruno Bottazzini <bruno.bottazzini@intel.com>2015-02-13 18:40:50 -0200
committerDavid Herrmann <dh.herrmann@gmail.com>2015-02-14 14:32:27 +0100
commit9cad100eca602aa33c2f56475c30fccf14abea1a (patch)
treea9fe2c9665ec219dc9c56b05f16894dd703c34d2 /src/shared/util.h
parent60c35566600f45350c37f152c1093018972bd9a5 (diff)
util: use a shared lookup function for string tables
Macro DEFINE_STRING_TABLE_LOOKUP expands to a new function for each of the almost 120 tables throghout the code. Move the its implementation to a function (guaranteed to never be inlined), and make the macro expand to an inlined function that calls this function. This saves a few kilobytes from the systemd binary (David: - fix coding-style - use 'ssize_t' to fix 32bit to 64bit propagation - use streq_ptr())
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index b56ffbde4..a83b58822 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -355,16 +355,11 @@ static inline uint32_t random_u32(void) {
return name##_table[i]; \
}
-#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \
- scope type name##_from_string(const char *s) { \
- type i; \
- if (!s) \
- return (type) -1; \
- for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
- if (name##_table[i] && \
- streq(name##_table[i], s)) \
- return i; \
- return (type) -1; \
+ssize_t string_table_lookup(const char * const *table, size_t len, const char *key);
+
+#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \
+ scope inline type name##_from_string(const char *s) { \
+ return (type)string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
}
#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \