* grub-core/kern/partition.c (grub_partition_get_name): Simplify logic
and improve performance.
This commit is contained in:
parent
5858b42d07
commit
f6c434d581
2 changed files with 18 additions and 22 deletions
|
@ -1,3 +1,8 @@
|
|||
2012-01-29 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* grub-core/kern/partition.c (grub_partition_get_name): Simplify logic
|
||||
and improve performance.
|
||||
|
||||
2012-01-29 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Fix
|
||||
|
|
|
@ -223,32 +223,23 @@ grub_partition_iterate (struct grub_disk *disk,
|
|||
char *
|
||||
grub_partition_get_name (const grub_partition_t partition)
|
||||
{
|
||||
char *out = 0;
|
||||
int curlen = 0;
|
||||
char *out = 0, *ptr;
|
||||
grub_size_t needlen = 0;
|
||||
grub_partition_t part;
|
||||
for (part = partition; part; part = part->parent)
|
||||
/* Even on 64-bit machines this buffer is enough to hold
|
||||
longest number. */
|
||||
needlen += grub_strlen (part->partmap->name) + 27;
|
||||
out = grub_malloc (needlen);
|
||||
if (!out)
|
||||
return NULL;
|
||||
|
||||
ptr = out;
|
||||
for (part = partition; part; part = part->parent)
|
||||
{
|
||||
/* Even on 64-bit machines this buffer is enough to hold
|
||||
longest number. */
|
||||
char buf[grub_strlen (part->partmap->name) + 25];
|
||||
int strl;
|
||||
grub_snprintf (buf, sizeof (buf), "%s%d", part->partmap->name,
|
||||
grub_snprintf (ptr, needlen - (out - ptr), "%s%d", part->partmap->name,
|
||||
part->number + 1);
|
||||
strl = grub_strlen (buf);
|
||||
if (curlen)
|
||||
{
|
||||
out = grub_realloc (out, curlen + strl + 2);
|
||||
grub_memcpy (out + strl + 1, out, curlen);
|
||||
out[curlen + 1 + strl] = 0;
|
||||
grub_memcpy (out, buf, strl);
|
||||
out[strl] = ',';
|
||||
curlen = curlen + 1 + strl;
|
||||
}
|
||||
else
|
||||
{
|
||||
curlen = strl;
|
||||
out = grub_strdup (buf);
|
||||
}
|
||||
ptr += grub_strlen (ptr);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue