|
From: <ssm...@us...> - 2007-08-29 13:02:13
|
Revision: 2543
http://selinux.svn.sourceforge.net/selinux/?rev=2543&view=rev
Author: ssmalley
Date: 2007-08-29 06:02:10 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
Author: Ulrich Drepper
Email: dr...@re...
Subject: libsepol optimization
Date: Tue, 28 Aug 2007 12:53:23 -0700
First in a series of 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.
Modified Paths:
--------------
trunk/libsepol/src/private.h
trunk/libsepol/src/services.c
Modified: trunk/libsepol/src/private.h
===================================================================
--- trunk/libsepol/src/private.h 2007-08-28 17:42:07 UTC (rev 2542)
+++ trunk/libsepol/src/private.h 2007-08-29 13:02:10 UTC (rev 2543)
@@ -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 @@
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;
Modified: trunk/libsepol/src/services.c
===================================================================
--- trunk/libsepol/src/services.c 2007-08-28 17:42:07 UTC (rev 2542)
+++ trunk/libsepol/src/services.c 2007-08-29 13:02:10 UTC (rev 2543)
@@ -927,6 +927,58 @@
return rc;
}
+/* Reading from a policy "file". */
+int hidden 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;
+}
+
+size_t hidden 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;
+}
+
/*
* Read a new set of configuration data from
* a policy database binary representation file.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|