libsepol optimization
First in a serious or changes proposed for libsepol.
The first is a little patch which shrinks the DSO by 4.3%. The next_entry and put_entry functions are marked inline. These are not good candidates, the code is too big. I bet without inlining them the code actually runs faster because the i-cache isn't so polluted. Plus the savings in memory of course.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
src/private.h +4 -49
@@ -7,6 +7,7 @@#include <byteswap.h> #include <endian.h> #include <errno.h> +#include <dso.h> #if __BYTE_ORDER == __LITTLE_ENDIAN#define cpu_to_le16 (x) (x)
@@ -41,52 +42,6 @@ extern struct policydb_compat_info *poli unsigned int type);/* Reading from a policy "file". */ -static inline int next_entry (void *buf,struct policy_file *fp,size_t bytes) -{ -size_t nread; - -switch (fp->type) { -case PF_USE_STDIO : - nread =fread (buf, bytes,1 , fp->fp); -if (nread !=1 ) -return -1 ; -break ; -case PF_USE_MEMORY : -if (bytes > fp->len) -return -1 ; -memcpy (buf, fp->data, bytes); - fp->data += bytes; - fp->len -= bytes; -break ; -default : -return -1 ; - } -return 0 ; -} - -static inline size_t put_entry (const void *ptr,size_t size,size_t n, -struct policy_file *fp) -{ -size_t bytes = size * n; - -switch (fp->type) { -case PF_USE_STDIO : -return fwrite (ptr, size, n, fp->fp); -case PF_USE_MEMORY : -if (bytes > fp->len) { - errno =ENOSPC ; -return 0 ; - } - -memcpy (fp->data, ptr, bytes); - fp->data += bytes; - fp->len -= bytes; -return n; -case PF_LEN : - fp->len += bytes; -return n; -default : -return 0 ; - } -return 0 ; -} +extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden; +extern size_t put_entry(const void *ptr, size_t size, size_t n, + struct policy_file *fp) hidden;
src/services.c +52 -0
58 lines not on this page · raw message