[gimp/metadata-browser] app: Don't overload head_size with different meanings
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] app: Don't overload head_size with different meanings
- Date: Fri, 2 Dec 2011 02:00:56 +0000 (UTC)
commit 3fbbe2d1861cabfdcfadc775d5aa792b8ba981f9
Author: Mukund Sivaraman <muks banu com>
Date: Sun Oct 2 18:35:26 2011 +0530
app: Don't overload head_size with different meanings
The code in file_procedure_find() tries to lazy-open the image file, so
it's not opened if unnecessary. To keep track of whether the image was
opened or not, it overrides head_size to keep track of this. head_size
is also assigned the return value of fread() in the loop. The patch
separates this by introducing another variable.
I think it's best to move the file opening code outside the while loop,
as it's most likely bound to be opened anyway, and the penalty is not
too bad.
app/file/file-procedure.c | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/app/file/file-procedure.c b/app/file/file-procedure.c
index 146d9d7..375339a 100644
--- a/app/file/file-procedure.c
+++ b/app/file/file-procedure.c
@@ -113,7 +113,8 @@ file_procedure_find (GSList *procs,
{
GimpPlugInProcedure *size_matched_proc = NULL;
FILE *ifp = NULL;
- gint head_size = -2;
+ gboolean opened = FALSE;
+ gint head_size = 0;
gint size_match_count = 0;
guchar head[256];
@@ -124,21 +125,17 @@ file_procedure_find (GSList *procs,
if (file_proc->magics_list)
{
- if (head_size == -2)
+ if (G_UNLIKELY (!opened))
{
- head_size = 0;
-
- if ((ifp = g_fopen (filename, "rb")) != NULL)
- {
- head_size = fread ((gchar *) head, 1, sizeof (head), ifp);
- }
+ ifp = g_fopen (filename, "rb");
+ if (ifp != NULL)
+ head_size = fread ((gchar *) head, 1, sizeof (head), ifp);
else
- {
- g_set_error_literal (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- g_strerror (errno));
- }
+ g_set_error_literal (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ g_strerror (errno));
+ opened = TRUE;
}
if (head_size >= 4)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]