Replace single-linked with double-linked lists. It results in more
compact and more efficient code. * grub-core/kern/list.c (grub_list_push): Moved from here ... * include/grub/list.h (grub_list_push): ... to here. Set prev. (grub_list_remove): Moved from here ... * include/grub/list.h (grub_list_remove): ... here. Use and set prev. (grub_prio_list_insert): Set prev. * include/grub/list.h (grub_list): Add prev. All users updated.
This commit is contained in:
parent
48b391e9ab
commit
87edb8940a
27 changed files with 111 additions and 75 deletions
|
@ -340,7 +340,7 @@ grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
|
|||
void
|
||||
grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&attach_hooks), GRUB_AS_LIST (desc));
|
||||
grub_list_remove (GRUB_AS_LIST (desc));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ struct grub_term_autoload *grub_term_output_autoload = NULL;
|
|||
struct abstract_terminal
|
||||
{
|
||||
struct abstract_terminal *next;
|
||||
struct abstract_terminal *prev;
|
||||
const char *name;
|
||||
grub_err_t (*init) (struct abstract_terminal *term);
|
||||
grub_err_t (*fini) (struct abstract_terminal *term);
|
||||
|
@ -137,7 +138,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
if (term->init && term->init (term) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +157,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
if (!term->next && term == *enabled)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"can't remove the last terminal");
|
||||
grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
if (term->fini)
|
||||
term->fini (term);
|
||||
grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
|
@ -174,7 +175,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
if (term->init && term->init (term) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
if (!term->next && term == *enabled)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"can't remove the last terminal");
|
||||
grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
if (term->fini)
|
||||
term->fini (term);
|
||||
grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
|
@ -208,6 +209,7 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
|
|||
int argc, char **args)
|
||||
{
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, next);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, prev);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, name);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, init);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, fini);
|
||||
|
@ -224,6 +226,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)),
|
|||
int argc, char **args)
|
||||
{
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, next);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, prev);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, name);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, init);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, fini);
|
||||
|
|
|
@ -121,6 +121,7 @@ enum
|
|||
struct grub_ahci_device
|
||||
{
|
||||
struct grub_ahci_device *next;
|
||||
struct grub_ahci_device **prev;
|
||||
volatile struct grub_ahci_hba *hba;
|
||||
int port;
|
||||
int num;
|
||||
|
|
|
@ -46,6 +46,7 @@ static const char *(*grub_gettext_original) (const char *s);
|
|||
struct grub_gettext_msg
|
||||
{
|
||||
struct grub_gettext_msg *next;
|
||||
struct grub_gettext_msg *prev;
|
||||
const char *name;
|
||||
|
||||
const char *translated;
|
||||
|
|
|
@ -52,7 +52,6 @@ grub_register_command_prio (const char *name,
|
|||
void
|
||||
grub_unregister_command (grub_command_t cmd)
|
||||
{
|
||||
grub_prio_list_remove (GRUB_AS_PRIO_LIST_P (&grub_command_list),
|
||||
GRUB_AS_PRIO_LIST (cmd));
|
||||
grub_prio_list_remove (GRUB_AS_PRIO_LIST (cmd));
|
||||
grub_free (cmd);
|
||||
}
|
||||
|
|
|
@ -635,6 +635,7 @@ devmapper_fail:
|
|||
struct linux_partition_cache
|
||||
{
|
||||
struct linux_partition_cache *next;
|
||||
struct linux_partition_cache **prev;
|
||||
char *dev;
|
||||
unsigned long start;
|
||||
int partno;
|
||||
|
|
|
@ -21,26 +21,6 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
|
||||
void
|
||||
grub_list_push (grub_list_t *head, grub_list_t item)
|
||||
{
|
||||
item->next = *head;
|
||||
*head = item;
|
||||
}
|
||||
|
||||
void
|
||||
grub_list_remove (grub_list_t *head, grub_list_t item)
|
||||
{
|
||||
grub_list_t *p, q;
|
||||
|
||||
for (p = head, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (q == item)
|
||||
{
|
||||
*p = q->next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
grub_named_list_find (grub_named_list_t head, const char *name)
|
||||
{
|
||||
|
@ -81,6 +61,9 @@ grub_prio_list_insert (grub_prio_list_t *head, grub_prio_list_t nitem)
|
|||
|
||||
*p = nitem;
|
||||
nitem->next = q;
|
||||
if (q)
|
||||
q->prev = &nitem->next;
|
||||
nitem->prev = p;
|
||||
|
||||
if (! inactive)
|
||||
nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
|
||||
|
|
|
@ -58,6 +58,7 @@ static struct tbl_alias table_aliases[] =
|
|||
struct grub_xnu_devprop_device_descriptor
|
||||
{
|
||||
struct grub_xnu_devprop_device_descriptor *next;
|
||||
struct grub_xnu_devprop_device_descriptor **prev;
|
||||
struct property_descriptor *properties;
|
||||
struct grub_efi_device_path *path;
|
||||
int pathlen;
|
||||
|
@ -212,6 +213,7 @@ guessfsb (void)
|
|||
struct property_descriptor
|
||||
{
|
||||
struct property_descriptor *next;
|
||||
struct property_descriptor **prev;
|
||||
grub_uint8_t *name;
|
||||
grub_uint16_t *name16;
|
||||
int name16len;
|
||||
|
@ -234,7 +236,7 @@ grub_xnu_devprop_remove_property (struct grub_xnu_devprop_device_descriptor *dev
|
|||
grub_free (prop->name16);
|
||||
grub_free (prop->data);
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (&dev->properties), GRUB_AS_LIST (prop));
|
||||
grub_list_remove (GRUB_AS_LIST (prop));
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
@ -245,7 +247,7 @@ grub_xnu_devprop_remove_device (struct grub_xnu_devprop_device_descriptor *dev)
|
|||
void *t;
|
||||
struct property_descriptor *prop;
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (&devices), GRUB_AS_LIST (dev));
|
||||
grub_list_remove (GRUB_AS_LIST (dev));
|
||||
|
||||
for (prop = dev->properties; prop; )
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ char *grub_net_default_server;
|
|||
struct grub_net_route
|
||||
{
|
||||
struct grub_net_route *next;
|
||||
struct grub_net_route **prev;
|
||||
grub_net_network_level_netaddress_t target;
|
||||
char *name;
|
||||
struct grub_net_network_level_protocol *prot;
|
||||
|
@ -206,8 +207,7 @@ grub_net_card_unregister (struct grub_net_card *card)
|
|||
card->driver->close (card);
|
||||
card->opened = 0;
|
||||
}
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards),
|
||||
GRUB_AS_LIST (card));
|
||||
grub_list_remove (GRUB_AS_LIST (card));
|
||||
}
|
||||
|
||||
static struct grub_net_slaac_mac_list *
|
||||
|
@ -366,8 +366,7 @@ grub_net_route_register (struct grub_net_route *route)
|
|||
static inline void
|
||||
grub_net_route_unregister (struct grub_net_route *route)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_net_routes),
|
||||
GRUB_AS_LIST (route));
|
||||
grub_list_remove (GRUB_AS_LIST (route));
|
||||
}
|
||||
|
||||
#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next)
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
struct unacked
|
||||
{
|
||||
struct unacked *next;
|
||||
struct unacked **prev;
|
||||
struct grub_net_buff *nb;
|
||||
grub_uint64_t last_try;
|
||||
int try_count;
|
||||
|
@ -49,6 +50,7 @@ enum
|
|||
struct grub_net_tcp_socket
|
||||
{
|
||||
struct grub_net_tcp_socket *next;
|
||||
struct grub_net_tcp_socket **prev;
|
||||
|
||||
int established;
|
||||
int i_closed;
|
||||
|
@ -80,6 +82,7 @@ struct grub_net_tcp_socket
|
|||
struct grub_net_tcp_listen
|
||||
{
|
||||
struct grub_net_tcp_listen *next;
|
||||
struct grub_net_tcp_listen **prev;
|
||||
|
||||
grub_uint16_t port;
|
||||
const struct grub_net_network_level_interface *inf;
|
||||
|
@ -149,8 +152,7 @@ grub_net_tcp_listen (grub_uint16_t port,
|
|||
void
|
||||
grub_net_tcp_stop_listen (grub_net_tcp_listen_t listen)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&tcp_listens),
|
||||
GRUB_AS_LIST (listen));
|
||||
grub_list_remove (GRUB_AS_LIST (listen));
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -640,8 +642,7 @@ grub_net_tcp_open (char *server,
|
|||
GRUB_NET_IP_TCP);
|
||||
if (err)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&tcp_sockets),
|
||||
GRUB_AS_LIST (socket));
|
||||
grub_list_remove (GRUB_AS_LIST (socket));
|
||||
grub_free (socket);
|
||||
grub_netbuff_free (nb);
|
||||
return NULL;
|
||||
|
@ -654,8 +655,7 @@ grub_net_tcp_open (char *server,
|
|||
}
|
||||
if (!socket->established)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&tcp_sockets),
|
||||
GRUB_AS_LIST (socket));
|
||||
grub_list_remove (GRUB_AS_LIST (socket));
|
||||
if (socket->they_reseted)
|
||||
grub_error (GRUB_ERR_NET_PORT_CLOSED, "port closed");
|
||||
else
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
struct grub_net_udp_socket
|
||||
{
|
||||
struct grub_net_udp_socket *next;
|
||||
struct grub_net_udp_socket **prev;
|
||||
|
||||
enum { GRUB_NET_SOCKET_START,
|
||||
GRUB_NET_SOCKET_ESTABLISHED,
|
||||
|
@ -53,8 +54,7 @@ udp_socket_register (grub_net_udp_socket_t sock)
|
|||
void
|
||||
grub_net_udp_close (grub_net_udp_socket_t sock)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&udp_sockets),
|
||||
GRUB_AS_LIST (sock));
|
||||
grub_list_remove (GRUB_AS_LIST (sock));
|
||||
grub_free (sock);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
struct grub_auth_user
|
||||
{
|
||||
struct grub_auth_user *next;
|
||||
struct grub_auth_user **prev;
|
||||
char *name;
|
||||
grub_auth_callback_t callback;
|
||||
void *arg;
|
||||
|
@ -73,7 +74,7 @@ grub_auth_unregister_authentication (const char *user)
|
|||
if (!cur->authenticated)
|
||||
{
|
||||
grub_free (cur->name);
|
||||
grub_list_remove (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur));
|
||||
grub_list_remove (GRUB_AS_LIST (cur));
|
||||
grub_free (cur);
|
||||
}
|
||||
else
|
||||
|
@ -121,7 +122,7 @@ grub_auth_deauthenticate (const char *user)
|
|||
if (!cur->callback)
|
||||
{
|
||||
grub_free (cur->name);
|
||||
grub_list_remove (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur));
|
||||
grub_list_remove (GRUB_AS_LIST (cur));
|
||||
grub_free (cur);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -350,7 +350,7 @@ grub_serial_unregister (struct grub_serial_port *port)
|
|||
if (port->term_out)
|
||||
grub_term_unregister_output (port->term_out);
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_serial_ports), GRUB_AS_LIST (port));
|
||||
grub_list_remove (GRUB_AS_LIST (port));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -24,6 +24,7 @@ struct grub_test_failure
|
|||
{
|
||||
/* The next failure. */
|
||||
struct grub_test_failure *next;
|
||||
struct grub_test_failure **prev;
|
||||
|
||||
/* The test source file name. */
|
||||
char *file;
|
||||
|
@ -124,7 +125,7 @@ grub_test_unregister (const char *name)
|
|||
|
||||
if (test)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test));
|
||||
grub_list_remove (GRUB_AS_LIST (test));
|
||||
|
||||
if (test->name)
|
||||
grub_free (test->name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue