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.
+2012-01-24 Vladimir Serbinenko <phcoder@gmail.com>
+
+ 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.
+
2012-01-24 Vladimir Serbinenko <phcoder@gmail.com>
Handle newer autotools. Add some missing quotes while on it.
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));
}
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);
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));
}
}
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));
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));
}
}
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));
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);
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);
struct grub_ahci_device
{
struct grub_ahci_device *next;
+ struct grub_ahci_device **prev;
volatile struct grub_ahci_hba *hba;
int port;
int num;
struct grub_gettext_msg
{
struct grub_gettext_msg *next;
+ struct grub_gettext_msg *prev;
const char *name;
const char *translated;
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);
}
struct linux_partition_cache
{
struct linux_partition_cache *next;
+ struct linux_partition_cache **prev;
char *dev;
unsigned long start;
int partno;
#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)
{
*p = nitem;
nitem->next = q;
+ if (q)
+ q->prev = &nitem->next;
+ nitem->prev = p;
if (! inactive)
nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
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;
struct property_descriptor
{
struct property_descriptor *next;
+ struct property_descriptor **prev;
grub_uint8_t *name;
grub_uint16_t *name16;
int name16len;
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;
}
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; )
{
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;
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 *
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)
struct unacked
{
struct unacked *next;
+ struct unacked **prev;
struct grub_net_buff *nb;
grub_uint64_t last_try;
int try_count;
struct grub_net_tcp_socket
{
struct grub_net_tcp_socket *next;
+ struct grub_net_tcp_socket **prev;
int established;
int i_closed;
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;
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
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;
}
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
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,
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);
}
struct grub_auth_user
{
struct grub_auth_user *next;
+ struct grub_auth_user **prev;
char *name;
grub_auth_callback_t callback;
void *arg;
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
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
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
{
/* The next failure. */
struct grub_test_failure *next;
+ struct grub_test_failure **prev;
/* The test source file name. */
char *file;
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);
{
/* The next element. */
struct grub_command *next;
+ struct grub_command **prev;
/* The name. */
const char *name;
struct grub_cryptodisk
{
struct grub_cryptodisk *next;
+ struct grub_cryptodisk **prev;
char *source;
grub_disk_addr_t offset;
struct grub_cryptodisk_dev
{
struct grub_cryptodisk_dev *next;
+ struct grub_cryptodisk_dev **prev;
grub_cryptodisk_t (*scan) (grub_disk_t disk, const char *check_uuid,
int boot_only);
static inline void
grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr));
+ grub_list_remove (GRUB_AS_LIST (cr));
}
#define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list))
{
/* The next filesystem. */
struct grub_fs *next;
+ struct grub_fs **prev;
/* My name. */
const char *name;
static inline void
grub_fs_unregister (grub_fs_t fs)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
+ grub_list_remove (GRUB_AS_LIST (fs));
}
#define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
struct grub_list
{
struct grub_list *next;
+ struct grub_list **prev;
};
typedef struct grub_list *grub_list_t;
-void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
-void EXPORT_FUNC(grub_list_remove) (grub_list_t *head, grub_list_t item);
+static inline void
+grub_list_push (grub_list_t *head, grub_list_t item)
+{
+ item->prev = head;
+ if (*head)
+ (*head)->prev = &item->next;
+ item->next = *head;
+ *head = item;
+}
+
+static inline void
+grub_list_remove (grub_list_t item)
+{
+ *item->prev = item->next;
+ if (item->next)
+ item->next->prev = item->prev;
+}
#define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)
((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
#define GRUB_AS_LIST(ptr) \
- (GRUB_FIELD_MATCH (ptr, grub_list_t, next) ? \
+ (GRUB_FIELD_MATCH (ptr, grub_list_t, next) && GRUB_FIELD_MATCH (ptr, grub_list_t, prev) ? \
(grub_list_t) ptr : (grub_list_t) grub_bad_type_cast ())
#define GRUB_AS_LIST_P(pptr) \
- (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) ? \
+ (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) && GRUB_FIELD_MATCH (*pptr, grub_list_t, prev) ? \
(grub_list_t *) (void *) pptr : (grub_list_t *) grub_bad_type_cast ())
struct grub_named_list
{
struct grub_named_list *next;
+ struct grub_named_list **prev;
char *name;
};
typedef struct grub_named_list *grub_named_list_t;
const char *name);
#define GRUB_AS_NAMED_LIST(ptr) \
- ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) && \
- GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \
+ ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) \
+ && GRUB_FIELD_MATCH (ptr, grub_named_list_t, prev) \
+ && GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \
(grub_named_list_t) ptr : (grub_named_list_t) grub_bad_type_cast ())
#define GRUB_AS_NAMED_LIST_P(pptr) \
- ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) && \
- GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
+ ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) \
+ && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, prev) \
+ && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
(grub_named_list_t *) (void *) pptr : (grub_named_list_t *) grub_bad_type_cast ())
#define GRUB_PRIO_LIST_PRIO_MASK 0xff
struct grub_prio_list
{
struct grub_prio_list *next;
+ struct grub_prio_list **prev;
char *name;
int prio;
};
grub_prio_list_t item);
static inline void
-grub_prio_list_remove (grub_prio_list_t *head, grub_prio_list_t item)
+grub_prio_list_remove (grub_prio_list_t item)
{
if ((item->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (item->next))
item->next->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
- grub_list_remove (GRUB_AS_LIST_P (head), GRUB_AS_LIST (item));
+ grub_list_remove (GRUB_AS_LIST (item));
}
#define GRUB_AS_PRIO_LIST(ptr) \
- ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) && \
- GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) && \
- GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \
+ ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) \
+ && GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prev) \
+ && GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) \
+ && GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \
(grub_prio_list_t) ptr \
: (grub_prio_list_t) grub_bad_type_cast ())
#define GRUB_AS_PRIO_LIST_P(pptr) \
- ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) && \
- GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) && \
- GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio)) ? \
+ ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) \
+ && GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prev) \
+ && GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) \
+ && GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio)) ? \
(grub_prio_list_t *) (void *) pptr \
: (grub_prio_list_t *) grub_bad_type_cast ())
struct grub_net_card_driver
{
struct grub_net_card_driver *next;
+ struct grub_net_card_driver **prev;
const char *name;
grub_err_t (*open) (const struct grub_net_card *dev);
void (*close) (const struct grub_net_card *dev);
struct grub_net_slaac_mac_list
{
struct grub_net_slaac_mac_list *next;
+ struct grub_net_slaac_mac_list **prev;
grub_net_link_level_address_t address;
int slaac_counter;
char *name;
struct grub_net_card
{
struct grub_net_card *next;
+ struct grub_net_card **prev;
const char *name;
struct grub_net_card_driver *driver;
grub_net_link_level_address_t default_address;
struct grub_net_app_protocol
{
struct grub_net_app_protocol *next;
+ struct grub_net_app_protocol **prev;
const char *name;
grub_err_t (*dir) (grub_device_t device, const char *path,
int (*hook) (const char *filename,
static inline void
grub_net_app_level_unregister (grub_net_app_level_t proto)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_net_app_level_list),
- GRUB_AS_LIST (proto));
+ grub_list_remove (GRUB_AS_LIST (proto));
}
#define FOR_NET_APP_LEVEL(var) FOR_LIST_ELEMENTS((var), \
{
/* The next partition map type. */
struct grub_partition_map *next;
+ struct grub_partition_map **prev;
/* The name of the partition map type. */
const char *name;
static inline void
grub_partition_map_unregister (grub_partition_map_t partmap)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_partition_map_list),
- GRUB_AS_LIST (partmap));
+ grub_list_remove (GRUB_AS_LIST (partmap));
}
#define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list))
struct grub_serial_port
{
struct grub_serial_port *next;
+ struct grub_serial_port **prev;
char *name;
struct grub_serial_driver *driver;
struct grub_serial_config config;
{
/* The next terminal. */
struct grub_term_input *next;
+ struct grub_term_input **prev;
/* The terminal name. */
const char *name;
{
/* The next terminal. */
struct grub_term_output *next;
+ struct grub_term_output **prev;
/* The terminal name. */
const char *name;
static inline void
grub_term_unregister_input (grub_term_input_t term)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term));
- grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
- GRUB_AS_LIST (term));
+ grub_list_remove (GRUB_AS_LIST (term));
+ grub_list_remove (GRUB_AS_LIST (term));
}
static inline void
grub_term_unregister_output (grub_term_output_t term)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term));
- grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)),
- GRUB_AS_LIST (term));
+ grub_list_remove (GRUB_AS_LIST (term));
+ grub_list_remove (GRUB_AS_LIST (term));
}
#define FOR_ACTIVE_TERM_INPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_inputs))
{
/* The next test. */
struct grub_test *next;
+ struct grub_test **prev;
/* The test name. */
char *name;
struct grub_usb_attach_desc
{
struct grub_usb_attach_desc *next;
+ struct grub_usb_attach_desc **prev;
int class;
grub_usb_attach_hook_class hook;
};
{
/* The next video adapter. */
struct grub_video_adapter *next;
+ struct grub_video_adapter **prev;
/* The video adapter name. */
const char *name;
static inline void
grub_video_unregister (grub_video_adapter_t adapter)
{
- grub_list_remove (GRUB_AS_LIST_P (&grub_video_adapter_list),
- GRUB_AS_LIST (adapter));
+ grub_list_remove (GRUB_AS_LIST (adapter));
}
#define FOR_VIDEO_ADAPTERS(var) FOR_LIST_ELEMENTS((var), (grub_video_adapter_list))
static struct seen_device
{
struct seen_device *next;
+ struct seen_device **prev;
const char *name;
} *seen;