[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Simplify and optimize grub_device_iterate()
From: |
Pavel Roskin |
Subject: |
[PATCH] Simplify and optimize grub_device_iterate() |
Date: |
Wed, 08 Jul 2009 18:59:14 -0400 |
User-agent: |
StGIT/0.14.3 |
I wanted to switch the partition buffering from LIFO to FIFO, but it
would increase the core size for a cosmetic improvement in the ls
output. This patch is a side effect of me touching that function.
ChangeLog:
* kern/device.c (grub_device_iterate): Change struct part_ent to
hold the name, not a pointer to it. Use one grub_malloc(), not
two. Free partition_name if grub_malloc() fails. Set ents to
NULL only before grub_partition_iterate() is called.
---
kern/device.c | 16 +++++-----------
1 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/kern/device.c b/kern/device.c
index 55c750b..83ae3dc 100644
--- a/kern/device.c
+++ b/kern/device.c
@@ -86,8 +86,8 @@ grub_device_iterate (int (*hook) (const char *name))
struct part_ent
{
struct part_ent *next;
- char *name;
- } *ents = NULL;
+ char name[0];
+ } *ents;
int iterate_disk (const char *disk_name)
{
@@ -105,18 +105,17 @@ grub_device_iterate (int (*hook) (const char *name))
struct part_ent *p;
int ret = 0;
+ ents = NULL;
(void) grub_partition_iterate (dev->disk, iterate_partition);
grub_device_close (dev);
p = ents;
- ents = NULL;
while (p != NULL)
{
struct part_ent *next = p->next;
if (!ret)
ret = hook (p->name);
- grub_free (p->name);
grub_free (p);
p = next;
}
@@ -137,15 +136,10 @@ grub_device_iterate (int (*hook) (const char *name))
if (! partition_name)
return 1;
- p = grub_malloc (sizeof (*p));
+ p = grub_malloc (sizeof (p->next) + grub_strlen (disk->name) + 1 +
+ grub_strlen (partition_name) + 1);
if (!p)
- return 1;
-
- p->name = grub_malloc (grub_strlen (disk->name) + 1
- + grub_strlen (partition_name) + 1);
- if (! p->name)
{
- grub_free (p);
grub_free (partition_name);
return 1;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Simplify and optimize grub_device_iterate(),
Pavel Roskin <=