Commit bb237831 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Convert Request from struct of gboolean to guin32 bitfield. This is both

2009-01-13  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-directory-async.c:
        * libnautilus-private/nautilus-directory-private.h:
        * libnautilus-private/nautilus-file.c:
	Convert Request from struct of gboolean to guin32 bitfield.
	This is both smaller and faster, plus it allows some further optimizations to come.


svn path=/trunk/; revision=14846
parent 4def951e
2009-01-13 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory-async.c:
* libnautilus-private/nautilus-directory-private.h:
* libnautilus-private/nautilus-file.c:
Convert Request from struct of gboolean to guin32 bitfield.
This is both smaller and faster, plus it allows some further optimizations to come.
2009-01-13 Alexander Larsson <alexl@redhat.com> 2009-01-13 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-icon-container.c: * libnautilus-private/nautilus-icon-container.c:
......
...@@ -172,7 +172,7 @@ typedef struct { ...@@ -172,7 +172,7 @@ typedef struct {
NautilusOperationResult result; NautilusOperationResult result;
} InfoProviderResponse; } InfoProviderResponse;
typedef gboolean (* RequestCheck) (const Request *); typedef gboolean (* RequestCheck) (Request);
typedef gboolean (* FileCheck) (NautilusFile *); typedef gboolean (* FileCheck) (NautilusFile *);
/* Current number of async. jobs. */ /* Current number of async. jobs. */
...@@ -190,7 +190,7 @@ static void deep_count_load (DeepCountState ...@@ -190,7 +190,7 @@ static void deep_count_load (DeepCountState
GFile *location); GFile *location);
static gboolean request_is_satisfied (NautilusDirectory *directory, static gboolean request_is_satisfied (NautilusDirectory *directory,
NautilusFile *file, NautilusFile *file,
Request *request); Request request);
static void cancel_loading_attributes (NautilusDirectory *directory, static void cancel_loading_attributes (NautilusDirectory *directory,
NautilusFileAttributes file_attributes); NautilusFileAttributes file_attributes);
static void add_all_files_to_work_queue (NautilusDirectory *directory); static void add_all_files_to_work_queue (NautilusDirectory *directory);
...@@ -594,51 +594,66 @@ remove_monitor (NautilusDirectory *directory, ...@@ -594,51 +594,66 @@ remove_monitor (NautilusDirectory *directory,
remove_monitor_link (directory, find_monitor (directory, file, client)); remove_monitor_link (directory, find_monitor (directory, file, client));
} }
void Request
nautilus_directory_set_up_request (Request *request, nautilus_directory_set_up_request (NautilusFileAttributes file_attributes)
NautilusFileAttributes file_attributes)
{ {
memset (request, 0, sizeof (*request)); Request request;
request = 0;
if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT) != 0) {
REQUEST_SET_TYPE (request, REQUEST_DIRECTORY_COUNT);
}
request->directory_count = if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS) != 0) {
(file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT) != 0; REQUEST_SET_TYPE (request, REQUEST_DEEP_COUNT);
request->deep_count = }
(file_attributes & NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS) != 0;
request->mime_list = if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES) != 0) {
(file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES) != 0; REQUEST_SET_TYPE (request, REQUEST_MIME_LIST);
request->file_info = (file_attributes & NAUTILUS_FILE_ATTRIBUTE_INFO) != 0; }
if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_INFO) != 0) {
REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
}
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_LINK_INFO) { if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_LINK_INFO) {
request->file_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
request->link_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_LINK_INFO);
} }
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT) { if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT) {
request->top_left_text = TRUE; REQUEST_SET_TYPE (request, REQUEST_TOP_LEFT_TEXT);
request->file_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
} }
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_LARGE_TOP_LEFT_TEXT) { if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_LARGE_TOP_LEFT_TEXT) {
request->large_top_left_text = TRUE; REQUEST_SET_TYPE (request, REQUEST_LARGE_TOP_LEFT_TEXT);
request->file_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
} }
request->metafile |= (file_attributes & NAUTILUS_FILE_ATTRIBUTE_METADATA) != 0; if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_METADATA) != 0) {
request->extension_info = (file_attributes & NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO) != 0; REQUEST_SET_TYPE (request, REQUEST_METAFILE);
}
if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO) != 0) {
REQUEST_SET_TYPE (request, REQUEST_EXTENSION_INFO);
}
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL) { if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL) {
request->thumbnail = TRUE; REQUEST_SET_TYPE (request, REQUEST_THUMBNAIL);
request->file_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
} }
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_MOUNT) { if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_MOUNT) {
request->mount = TRUE; REQUEST_SET_TYPE (request, REQUEST_MOUNT);
request->file_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
} }
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO) { if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO) {
request->filesystem_info = TRUE; REQUEST_SET_TYPE (request, REQUEST_FILESYSTEM_INFO);
} }
return request;
} }
static void static void
...@@ -681,9 +696,11 @@ nautilus_directory_monitor_add_internal (NautilusDirectory *directory, ...@@ -681,9 +696,11 @@ nautilus_directory_monitor_add_internal (NautilusDirectory *directory,
monitor->monitor_hidden_files = monitor_hidden_files; monitor->monitor_hidden_files = monitor_hidden_files;
monitor->monitor_backup_files = monitor_backup_files; monitor->monitor_backup_files = monitor_backup_files;
monitor->client = client; monitor->client = client;
nautilus_directory_set_up_request (&monitor->request, file_attributes); monitor->request = nautilus_directory_set_up_request (file_attributes);
monitor->request.file_list = file == NULL; if (file == NULL) {
REQUEST_SET_TYPE (monitor->request, REQUEST_FILE_LIST);
}
directory->details->monitor_list = directory->details->monitor_list =
g_list_prepend (directory->details->monitor_list, monitor); g_list_prepend (directory->details->monitor_list, monitor);
...@@ -705,11 +722,13 @@ nautilus_directory_monitor_add_internal (NautilusDirectory *directory, ...@@ -705,11 +722,13 @@ nautilus_directory_monitor_add_internal (NautilusDirectory *directory,
/* We could just call update_metadata_monitors here, but we can be smarter /* We could just call update_metadata_monitors here, but we can be smarter
* since we know what monitor was just added. * since we know what monitor was just added.
*/ */
if (monitor->request.metafile && !directory->details->metafile_monitored) { if (REQUEST_WANTS_TYPE (monitor->request, REQUEST_METAFILE) &&
!directory->details->metafile_monitored) {
nautilus_directory_register_metadata_monitor (directory); nautilus_directory_register_metadata_monitor (directory);
} }
if (monitor->request.file_info && directory->details->mime_db_monitor == 0) { if (REQUEST_WANTS_TYPE (monitor->request, REQUEST_FILE_INFO) &&
directory->details->mime_db_monitor == 0) {
directory->details->mime_db_monitor = directory->details->mime_db_monitor =
g_signal_connect_object (nautilus_signaller_get_current (), g_signal_connect_object (nautilus_signaller_get_current (),
"mime_data_changed", "mime_data_changed",
...@@ -1076,14 +1095,14 @@ is_anyone_waiting_for_metafile (NautilusDirectory *directory) ...@@ -1076,14 +1095,14 @@ is_anyone_waiting_for_metafile (NautilusDirectory *directory)
for (node = directory->details->call_when_ready_list; node != NULL; node = node->next) { for (node = directory->details->call_when_ready_list; node != NULL; node = node->next) {
callback = node->data; callback = node->data;
if (callback->request.metafile) { if (REQUEST_WANTS_TYPE (callback->request, REQUEST_METAFILE)) {
return TRUE; return TRUE;
} }
} }
for (node = directory->details->monitor_list; node != NULL; node = node->next) { for (node = directory->details->monitor_list; node != NULL; node = node->next) {
monitor = node->data; monitor = node->data;
if (monitor->request.metafile) { if (REQUEST_WANTS_TYPE (monitor->request, REQUEST_METAFILE)) {
return TRUE; return TRUE;
} }
} }
...@@ -1262,7 +1281,8 @@ ready_callback_call (NautilusDirectory *directory, ...@@ -1262,7 +1281,8 @@ ready_callback_call (NautilusDirectory *directory,
callback->callback_data); callback->callback_data);
} }
} else if (callback->callback.directory != NULL) { } else if (callback->callback.directory != NULL) {
if (directory == NULL || !callback->request.file_list) { if (directory == NULL ||
!REQUEST_WANTS_TYPE (callback->request, REQUEST_FILE_LIST)) {
file_list = NULL; file_list = NULL;
} else { } else {
file_list = nautilus_directory_get_file_list (directory); file_list = nautilus_directory_get_file_list (directory);
...@@ -1301,8 +1321,10 @@ nautilus_directory_call_when_ready_internal (NautilusDirectory *directory, ...@@ -1301,8 +1321,10 @@ nautilus_directory_call_when_ready_internal (NautilusDirectory *directory,
callback.callback.file = file_callback; callback.callback.file = file_callback;
} }
callback.callback_data = callback_data; callback.callback_data = callback_data;
nautilus_directory_set_up_request (&callback.request, file_attributes); callback.request = nautilus_directory_set_up_request (file_attributes);
callback.request.file_list = wait_for_file_list; if (wait_for_file_list) {
REQUEST_SET_TYPE (callback.request, REQUEST_FILE_LIST);
}
/* Handle the NULL case. */ /* Handle the NULL case. */
if (directory == NULL) { if (directory == NULL) {
...@@ -1330,7 +1352,8 @@ nautilus_directory_call_when_ready_internal (NautilusDirectory *directory, ...@@ -1330,7 +1352,8 @@ nautilus_directory_call_when_ready_internal (NautilusDirectory *directory,
* We could just call update_metadata_monitors here, but we can be smarter * We could just call update_metadata_monitors here, but we can be smarter
* since we know what was just added. * since we know what was just added.
*/ */
if (callback.request.metafile && !directory->details->metafile_monitored) { if (REQUEST_WANTS_TYPE (callback.request, REQUEST_METAFILE) &&
!directory->details->metafile_monitored) {
nautilus_directory_register_metadata_monitor (directory); nautilus_directory_register_metadata_monitor (directory);
} }
...@@ -1353,8 +1376,8 @@ nautilus_directory_check_if_ready_internal (NautilusDirectory *directory, ...@@ -1353,8 +1376,8 @@ nautilus_directory_check_if_ready_internal (NautilusDirectory *directory,
g_assert (NAUTILUS_IS_DIRECTORY (directory)); g_assert (NAUTILUS_IS_DIRECTORY (directory));
nautilus_directory_set_up_request (&request, file_attributes); request = nautilus_directory_set_up_request (file_attributes);
return request_is_satisfied (directory, file, &request); return request_is_satisfied (directory, file, request);
} }
static void static void
...@@ -1620,9 +1643,9 @@ should_get_directory_count_now (NautilusFile *file) ...@@ -1620,9 +1643,9 @@ should_get_directory_count_now (NautilusFile *file)
} }
static gboolean static gboolean
wants_directory_count (const Request *request) wants_directory_count (Request request)
{ {
return request->directory_count; return REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT);
} }
static gboolean static gboolean
...@@ -1634,9 +1657,9 @@ lacks_top_left (NautilusFile *file) ...@@ -1634,9 +1657,9 @@ lacks_top_left (NautilusFile *file)
} }
static gboolean static gboolean
wants_top_left (const Request *request) wants_top_left (Request request)
{ {
return request->top_left_text; return REQUEST_WANTS_TYPE (request, REQUEST_TOP_LEFT_TEXT);
} }
static gboolean static gboolean
...@@ -1649,9 +1672,9 @@ lacks_large_top_left (NautilusFile *file) ...@@ -1649,9 +1672,9 @@ lacks_large_top_left (NautilusFile *file)
} }
static gboolean static gboolean
wants_large_top_left (const Request *request) wants_large_top_left (Request request)
{ {
return request->large_top_left_text; return REQUEST_WANTS_TYPE (request, REQUEST_LARGE_TOP_LEFT_TEXT);
} }
static gboolean static gboolean
...@@ -1668,15 +1691,15 @@ lacks_filesystem_info (NautilusFile *file) ...@@ -1668,15 +1691,15 @@ lacks_filesystem_info (NautilusFile *file)
} }
static gboolean static gboolean
wants_info (const Request *request) wants_info (Request request)
{ {
return request->file_info; return REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO);
} }
static gboolean static gboolean
wants_filesystem_info (const Request *request) wants_filesystem_info (Request request)
{ {
return request->filesystem_info; return REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO);
} }
static gboolean static gboolean
...@@ -1686,9 +1709,9 @@ lacks_deep_count (NautilusFile *file) ...@@ -1686,9 +1709,9 @@ lacks_deep_count (NautilusFile *file)
} }
static gboolean static gboolean
wants_deep_count (const Request *request) wants_deep_count (Request request)
{ {
return request->deep_count; return REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT);
} }
static gboolean static gboolean
...@@ -1705,9 +1728,9 @@ should_get_mime_list (NautilusFile *file) ...@@ -1705,9 +1728,9 @@ should_get_mime_list (NautilusFile *file)
} }
static gboolean static gboolean
wants_mime_list (const Request *request) wants_mime_list (Request request)
{ {
return request->mime_list; return REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST);
} }
static gboolean static gboolean
lacks_link_info (NautilusFile *file) lacks_link_info (NautilusFile *file)
...@@ -1726,9 +1749,9 @@ lacks_link_info (NautilusFile *file) ...@@ -1726,9 +1749,9 @@ lacks_link_info (NautilusFile *file)
} }
static gboolean static gboolean
wants_link_info (const Request *request) wants_link_info (Request request)
{ {
return request->link_info; return REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO);
} }
static gboolean static gboolean
...@@ -1738,9 +1761,9 @@ lacks_extension_info (NautilusFile *file) ...@@ -1738,9 +1761,9 @@ lacks_extension_info (NautilusFile *file)
} }
static gboolean static gboolean
wants_extension_info (const Request *request) wants_extension_info (Request request)
{ {
return request->extension_info; return REQUEST_WANTS_TYPE (request, REQUEST_EXTENSION_INFO);
} }
static gboolean static gboolean
...@@ -1752,9 +1775,9 @@ lacks_thumbnail (NautilusFile *file) ...@@ -1752,9 +1775,9 @@ lacks_thumbnail (NautilusFile *file)
} }
static gboolean static gboolean
wants_thumbnail (const Request *request) wants_thumbnail (Request request)
{ {
return request->thumbnail; return REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL);
} }
static gboolean static gboolean
...@@ -1778,9 +1801,9 @@ lacks_mount (NautilusFile *file) ...@@ -1778,9 +1801,9 @@ lacks_mount (NautilusFile *file)
} }
static gboolean static gboolean
wants_mount (const Request *request) wants_mount (Request request)
{ {
return request->mount; return REQUEST_WANTS_TYPE (request, REQUEST_MOUNT);
} }
static gboolean static gboolean
...@@ -1804,72 +1827,74 @@ has_problem (NautilusDirectory *directory, NautilusFile *file, FileCheck problem ...@@ -1804,72 +1827,74 @@ has_problem (NautilusDirectory *directory, NautilusFile *file, FileCheck problem
static gboolean static gboolean
request_is_satisfied (NautilusDirectory *directory, request_is_satisfied (NautilusDirectory *directory,
NautilusFile *file, NautilusFile *file,
Request *request) Request request)
{ {
if (request->metafile && !nautilus_directory_is_metadata_read (directory)) { if (REQUEST_WANTS_TYPE (request, REQUEST_METAFILE) &&
!nautilus_directory_is_metadata_read (directory)) {
return FALSE; return FALSE;
} }
if (request->file_list && !(directory->details->directory_loaded && if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_LIST) &&
!(directory->details->directory_loaded &&
directory->details->directory_loaded_sent_notification)) { directory->details->directory_loaded_sent_notification)) {
return FALSE; return FALSE;
} }
if (request->directory_count) { if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT)) {
if (has_problem (directory, file, lacks_directory_count)) { if (has_problem (directory, file, lacks_directory_count)) {
return FALSE; return FALSE;
} }
} }
if (request->file_info) { if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
if (has_problem (directory, file, lacks_info)) { if (has_problem (directory, file, lacks_info)) {
return FALSE; return FALSE;
} }
} }
if (request->filesystem_info) { if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO)) {
if (has_problem (directory, file, lacks_filesystem_info)) { if (has_problem (directory, file, lacks_filesystem_info)) {
return FALSE; return FALSE;
} }
} }
if (request->top_left_text) { if (REQUEST_WANTS_TYPE (request, REQUEST_TOP_LEFT_TEXT)) {
if (has_problem (directory, file, lacks_top_left)) { if (has_problem (directory, file, lacks_top_left)) {
return FALSE; return FALSE;
} }
} }
if (request->large_top_left_text) { if (REQUEST_WANTS_TYPE (request, REQUEST_LARGE_TOP_LEFT_TEXT)) {
if (has_problem (directory, file, lacks_large_top_left)) { if (has_problem (directory, file, lacks_large_top_left)) {
return FALSE; return FALSE;
} }
} }
if (request->deep_count) { if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT)) {
if (has_problem (directory, file, lacks_deep_count)) { if (has_problem (directory, file, lacks_deep_count)) {
return FALSE; return FALSE;
} }
} }
if (request->thumbnail) { if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL)) {
if (has_problem (directory, file, lacks_thumbnail)) { if (has_problem (directory, file, lacks_thumbnail)) {
return FALSE; return FALSE;
} }
} }
if (request->mount) { if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT)) {
if (has_problem (directory, file, lacks_mount)) { if (has_problem (directory, file, lacks_mount)) {
return FALSE; return FALSE;
} }
} }
if (request->mime_list) { if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
if (has_problem (directory, file, lacks_mime_list)) { if (has_problem (directory, file, lacks_mime_list)) {
return FALSE; return FALSE;
} }
} }
if (request->link_info) { if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO)) {
if (has_problem (directory, file, lacks_link_info)) { if (has_problem (directory, file, lacks_link_info)) {
return FALSE; return FALSE;
} }
...@@ -1951,7 +1976,7 @@ call_ready_callbacks (NautilusDirectory *directory) ...@@ -1951,7 +1976,7 @@ call_ready_callbacks (NautilusDirectory *directory)
next = node->next; next = node->next;
callback = node->data; callback = node->data;
if (callback->active && if (callback->active &&
request_is_satisfied (directory, callback->file, &callback->request)) { request_is_satisfied (directory, callback->file, callback->request)) {
callback->active = FALSE; callback->active = FALSE;
found_any = TRUE; found_any = TRUE;
} }
...@@ -2005,7 +2030,7 @@ nautilus_directory_is_anyone_monitoring_file_list (NautilusDirectory *directory) ...@@ -2005,7 +2030,7 @@ nautilus_directory_is_anyone_monitoring_file_list (NautilusDirectory *directory)
for (node = directory->details->call_when_ready_list; for (node = directory->details->call_when_ready_list;
node != NULL; node = node->next) { node != NULL; node = node->next) {
callback = node->data; callback = node->data;
if (callback->request.file_list) { if (REQUEST_WANTS_TYPE (callback->request, REQUEST_FILE_LIST)) {
return TRUE; return TRUE;
} }
} }
...@@ -2013,7 +2038,7 @@ nautilus_directory_is_anyone_monitoring_file_list (NautilusDirectory *directory) ...@@ -2013,7 +2038,7 @@ nautilus_directory_is_anyone_monitoring_file_list (NautilusDirectory *directory)
for (node = directory->details->monitor_list; for (node = directory->details->monitor_list;
node != NULL; node = node->next) { node != NULL; node = node->next) {
monitor = node->data; monitor = node->data;