* 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>
|
2012-01-29 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Fix
|
* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Fix
|
||||||
|
|
|
@ -223,32 +223,23 @@ grub_partition_iterate (struct grub_disk *disk,
|
||||||
char *
|
char *
|
||||||
grub_partition_get_name (const grub_partition_t partition)
|
grub_partition_get_name (const grub_partition_t partition)
|
||||||
{
|
{
|
||||||
char *out = 0;
|
char *out = 0, *ptr;
|
||||||
int curlen = 0;
|
grub_size_t needlen = 0;
|
||||||
grub_partition_t part;
|
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)
|
for (part = partition; part; part = part->parent)
|
||||||
{
|
{
|
||||||
/* Even on 64-bit machines this buffer is enough to hold
|
grub_snprintf (ptr, needlen - (out - ptr), "%s%d", part->partmap->name,
|
||||||
longest number. */
|
|
||||||
char buf[grub_strlen (part->partmap->name) + 25];
|
|
||||||
int strl;
|
|
||||||
grub_snprintf (buf, sizeof (buf), "%s%d", part->partmap->name,
|
|
||||||
part->number + 1);
|
part->number + 1);
|
||||||
strl = grub_strlen (buf);
|
ptr += grub_strlen (ptr);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue