summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>2008-10-21 11:11:41 +0100
committerKay Sievers <kay.sievers@vrfy.org>2008-10-21 13:56:23 +0200
commitbe18918f65eb88d34953e8083aa5ca1e2c16f86c (patch)
tree7cfe1fefafd0f9a01049f782d351228f184977e0
parentfa0e955a93ca7d7e90d286a68454c6bd808a1c01 (diff)
libudev: allocate udev_device->envp[] dynamically
Measured 2% _user_ cpu time reduction on EeePC coldplug. Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
-rw-r--r--udev/lib/libudev-device.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
index e4cbd8e689..86f7918d49 100644
--- a/udev/lib/libudev-device.c
+++ b/udev/lib/libudev-device.c
@@ -31,6 +31,8 @@
#include "libudev.h"
#include "libudev-private.h"
+#define ENVP_SIZE 128
+
struct udev_device {
int refcount;
struct udev *udev;
@@ -46,7 +48,7 @@ struct udev_device {
struct udev_list_node devlinks_list;
int devlinks_uptodate;
struct udev_list_node properties_list;
- char *envp[128];
+ char **envp;
int envp_uptodate;
char *driver;
int driver_set;
@@ -610,8 +612,11 @@ void udev_device_unref(struct udev_device *udev_device)
free(udev_device->devpath_old);
free(udev_device->physdevpath);
udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
- for (i = 0; i < ARRAY_SIZE(udev_device->envp) && udev_device->envp[i] != NULL; i++)
- free(udev_device->envp[i]);
+ if (udev_device->envp != NULL) {
+ for (i = 0; i < ENVP_SIZE && udev_device->envp[i] != NULL; i++)
+ free(udev_device->envp[i]);
+ free(udev_device->envp);
+ }
info(udev_device->udev, "udev_device: %p released\n", udev_device);
free(udev_device);
}
@@ -1013,14 +1018,18 @@ char **udev_device_get_properties_envp(struct udev_device *udev_device)
unsigned int i;
struct udev_list_entry *list_entry;
- for (i = 0; i < ARRAY_SIZE(udev_device->envp) && udev_device->envp[i] != NULL; i++)
- free(udev_device->envp[i]);
+ if (udev_device->envp) {
+ for (i = 0; i < 128 && udev_device->envp[i] != NULL; i++)
+ free(udev_device->envp[i]);
+ } else
+ udev_device->envp = malloc(sizeof(char *) * ENVP_SIZE);
+
i = 0;
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
asprintf(&udev_device->envp[i++], "%s=%s",
udev_list_entry_get_name(list_entry),
udev_list_entry_get_value(list_entry));
- if (i+1 >= ARRAY_SIZE(udev_device->envp))
+ if (i+1 >= ENVP_SIZE)
break;
}
udev_device->envp[i] = NULL;