[gnome-commander] GnomeCmdFile: minor speedups



commit 21741fc4163231bd880d4aa04f7b9c7c09178683
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Wed Feb 10 18:40:10 2010 +0100

    GnomeCmdFile: minor speedups
    
    The checks if GnomeCmdFile was '..' dir, were done using many strcmp(f->info->name, "."). The fix replaces multiple calls to strcmp() with fast comparison to GnomeCmdFile::is_dotdot evaluated during GnomeCmdFile creation.

 src/gnome-cmd-chmod-dialog.cc      |    3 +-
 src/gnome-cmd-chown-dialog.cc      |    3 +-
 src/gnome-cmd-delete-dialog.cc     |    4 +-
 src/gnome-cmd-file-list.cc         |   38 ++++++++++++++++++------------------
 src/gnome-cmd-file-list.h          |    2 +-
 src/gnome-cmd-file-props-dialog.cc |    2 +-
 src/gnome-cmd-file-selector.cc     |    6 ++--
 src/gnome-cmd-file.cc              |    6 +++-
 src/gnome-cmd-file.h               |    1 +
 src/gnome-cmd-quicksearch-popup.cc |    2 +-
 src/gnome-cmd-search-dialog.cc     |    3 +-
 11 files changed, 35 insertions(+), 35 deletions(-)
---
diff --git a/src/gnome-cmd-chmod-dialog.cc b/src/gnome-cmd-chmod-dialog.cc
index d756695..2dad872 100644
--- a/src/gnome-cmd-chmod-dialog.cc
+++ b/src/gnome-cmd-chmod-dialog.cc
@@ -89,8 +89,7 @@ static void do_chmod (GnomeCmdFile *in, GnomeVFSFilePermissions perm, gboolean r
         for (GList *tmp = files; tmp; tmp = tmp->next)
         {
             GnomeCmdFile *f = (GnomeCmdFile *) tmp->data;
-            if (strcmp (f->info->name, ".") != 0
-                && strcmp (f->info->name, "..") != 0
+            if (!f->is_dotdot && strcmp (f->info->name, ".") != 0
                 && !GNOME_VFS_FILE_INFO_SYMLINK(f->info))
             {
                 do_chmod (f, perm, TRUE, mode);
diff --git a/src/gnome-cmd-chown-dialog.cc b/src/gnome-cmd-chown-dialog.cc
index 86a4177..213c56c 100644
--- a/src/gnome-cmd-chown-dialog.cc
+++ b/src/gnome-cmd-chown-dialog.cc
@@ -76,8 +76,7 @@ static void do_chown (GnomeCmdFile *in, uid_t uid, gid_t gid, gboolean recurse)
         for (tmp = files; tmp; tmp = tmp->next)
         {
             GnomeCmdFile *f = (GnomeCmdFile *) tmp->data;
-            if (strcmp (f->info->name, ".") != 0
-                && strcmp (f->info->name, "..") != 0
+            if (!f->is_dotdot && strcmp (f->info->name, ".") != 0
                 && !GNOME_VFS_FILE_INFO_SYMLINK(f->info))
             {
                 do_chown (f, uid, gid, TRUE);
diff --git a/src/gnome-cmd-delete-dialog.cc b/src/gnome-cmd-delete-dialog.cc
index 0cd3259..13c4d08 100644
--- a/src/gnome-cmd-delete-dialog.cc
+++ b/src/gnome-cmd-delete-dialog.cc
@@ -166,7 +166,7 @@ static void perform_delete_operation (DeleteData *data)
     {
         GnomeCmdFile *f = (GnomeCmdFile *) i->data;
 
-        if (strcmp(f->info->name, "..") == 0 || strcmp(f->info->name, ".") == 0)
+        if (f->is_dotdot || strcmp(f->info->name, ".") == 0)
             continue;
 
         GnomeVFSURI *uri = gnome_cmd_file_get_uri (f);
@@ -269,7 +269,7 @@ void gnome_cmd_delete_dialog_show (GList *files)
         {
             GnomeCmdFile *f = (GnomeCmdFile *) g_list_nth_data (files, 0);
 
-            if (strcmp (f->info->name, "..") == 0)
+            if (f->is_dotdot)
                 return;
 
             gchar *fname = get_utf8 (f->info->name);
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index 733b276..95e73c1 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -372,7 +372,7 @@ void GnomeCmdFileList::select_file(GnomeCmdFile *f, gint row)
     g_return_if_fail (f != NULL);
     g_return_if_fail (f->info != NULL);
 
-    if (strcmp (f->info->name, "..") == 0)
+    if (f->is_dotdot)
         return;
 
     if (row == -1)
@@ -826,10 +826,10 @@ inline gint my_filesizecmp (GnomeVFSFileSize i1, GnomeVFSFileSize i2, gboolean r
 
 static gint sort_by_name (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     if (f1->info->type > f2->info->type)
@@ -846,10 +846,10 @@ static gint sort_by_name (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *
 
 static gint sort_by_ext (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     if (f1->info->type > f2->info->type)
@@ -876,10 +876,10 @@ static gint sort_by_ext (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *f
 
 static gint sort_by_dir (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     if (f1->info->type > f2->info->type)
@@ -909,10 +909,10 @@ static gint sort_by_dir (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *f
 
 static gint sort_by_size (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     gboolean raising = fl->priv->sort_raising[fl->priv->current_col];
@@ -932,10 +932,10 @@ static gint sort_by_size (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *
 
 static gint sort_by_perm (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     gboolean raising = fl->priv->sort_raising[fl->priv->current_col];
@@ -954,10 +954,10 @@ static gint sort_by_perm (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *
 
 static gint sort_by_date (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     gboolean raising = fl->priv->sort_raising[fl->priv->current_col];
@@ -976,10 +976,10 @@ static gint sort_by_date (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *
 
 static gint sort_by_owner (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     gboolean raising = fl->priv->sort_raising[fl->priv->current_col];
@@ -998,10 +998,10 @@ static gint sort_by_owner (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList
 
 static gint sort_by_group (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl)
 {
-    if (strcmp (f1->info->name, "..") == 0)
+    if (f1->is_dotdot)
         return -1;
 
-    if (strcmp (f2->info->name, "..") == 0)
+    if (f2->is_dotdot)
         return 1;
 
     gboolean raising = fl->priv->sort_raising[fl->priv->current_col];
@@ -1169,7 +1169,7 @@ static void on_file_clicked (GnomeCmdFileList *fl, GnomeCmdFile *f, GdkEventButt
             }
             else
                 if (event->button == 3)
-                    if (strcmp (f->info->name, "..") != 0)
+                    if (!f->is_dotdot)
                     {
                         if (gnome_cmd_data.right_mouse_button_mode == GnomeCmdData::RIGHT_BUTTON_SELECTS)
                         {
@@ -2304,7 +2304,7 @@ gboolean GnomeCmdFileList::file_is_wanted(GnomeCmdFile *f)
 
     if (strcmp (info->name, ".") == 0)
         return FALSE;
-    if (strcmp (info->name, "..") == 0)
+    if (f->is_dotdot)
         return FALSE;
     if (gnome_cmd_data.hide_type(info->type))
         return FALSE;
diff --git a/src/gnome-cmd-file-list.h b/src/gnome-cmd-file-list.h
index d92fabf..487aa03 100644
--- a/src/gnome-cmd-file-list.h
+++ b/src/gnome-cmd-file-list.h
@@ -202,7 +202,7 @@ inline GnomeCmdFile *GnomeCmdFileList::get_selected_file()
 {
     GnomeCmdFile *f = get_focused_file();
 
-    return !f || strcmp (f->info->name, "..") == 0 ? NULL : f;
+    return !f || f->is_dotdot ? NULL : f;
 }
 
 void gnome_cmd_file_list_compare_directories (GnomeCmdFileList *fl1, GnomeCmdFileList *fl2);
diff --git a/src/gnome-cmd-file-props-dialog.cc b/src/gnome-cmd-file-props-dialog.cc
index 6dee301..6a4c8d4 100644
--- a/src/gnome-cmd-file-props-dialog.cc
+++ b/src/gnome-cmd-file-props-dialog.cc
@@ -710,7 +710,7 @@ GtkWidget *gnome_cmd_file_props_dialog_create (GnomeCmdFile *f)
     g_return_val_if_fail (f != NULL, NULL);
     g_return_val_if_fail (f->info != NULL, NULL);
 
-    if (strcmp (f->info->name, "..") == 0)
+    if (f->is_dotdot)
         return NULL;
 
     GnomeCmdFilePropsDialogPrivate *data = g_new0 (GnomeCmdFilePropsDialogPrivate, 1);
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index 3649baa..559f486 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -162,7 +162,7 @@ inline void GnomeCmdFileSelector::update_selected_files_label()
         switch (f->info->type)
         {
             case GNOME_VFS_FILE_TYPE_DIRECTORY:
-                if (strcmp(f->info->name, "..") != 0)
+                if (!f->is_dotdot)
                 {
                     num_dirs++;
                     if (gnome_cmd_file_has_tree_size (f))
@@ -362,7 +362,7 @@ drag_data_received (GtkWidget          *widget,
         /* The drop was over a directory in the list, which means that the
          * xfer should be done to that directory instead of the current one in the list
          */
-        if (strcmp (f->info->name, "..") == 0)
+        if (f->is_dotdot)
             to = gnome_cmd_dir_get_parent (cwd);
         else
             to = gnome_cmd_dir_get_child (cwd, f->info->name);
@@ -623,7 +623,7 @@ static void do_file_specific_action (GnomeCmdFileSelector *fs, GnomeCmdFile *f)
     {
         fs->file_list()->invalidate_tree_size();
 
-        if (strcmp (f->info->name, "..") == 0)
+        if (f->is_dotdot)
             fs->goto_directory("..");
         else
             fs->set_directory(GNOME_CMD_DIR (f));
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index a84933e..c037b74 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -214,6 +214,8 @@ void gnome_cmd_file_setup (GnomeCmdFile *f, GnomeVFSFileInfo *info, GnomeCmdDir
     f->info = info;
     GNOME_CMD_FILE_INFO (f)->info = info;
 
+    f->is_dotdot = info->type==GNOME_VFS_FILE_TYPE_DIRECTORY && strcmp(info->name, "..")==0;    // check if file is '..'
+
     gchar *utf8_name;
 
     if (!gnome_cmd_data.case_sens_sort)
@@ -571,7 +573,7 @@ GnomeVFSFileSize gnome_cmd_file_get_tree_size (GnomeCmdFile *f)
     if (f->info->type != GNOME_VFS_FILE_TYPE_DIRECTORY)
         return f->info->size;
 
-    if (strcmp (f->info->name, "..") == 0)
+    if (f->is_dotdot)
         return 0;
 
     if (f->priv->tree_size != -1)
@@ -593,7 +595,7 @@ const gchar *gnome_cmd_file_get_tree_size_as_str (GnomeCmdFile *f)
     if (f->info->type != GNOME_VFS_FILE_TYPE_DIRECTORY)
         return gnome_cmd_file_get_size (f);
 
-    if (strcmp (f->info->name, "..") == 0)
+    if (f->is_dotdot)
         return gnome_cmd_file_get_size (f);
 
     return size2string (gnome_cmd_file_get_tree_size (f), gnome_cmd_data.size_disp_mode);
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index aa834ca..c323ec4 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -37,6 +37,7 @@ struct GnomeCmdFile
     GnomeCmdFileInfo parent;
 
     GnomeVFSFileInfo *info;
+    gboolean is_dotdot;
     gchar *collate_key;                 // necessary for proper sorting of UTF-8 encoded file names
     GnomeCmdFilePrivate *priv;
     GnomeCmdFileMetadata *metadata;
diff --git a/src/gnome-cmd-quicksearch-popup.cc b/src/gnome-cmd-quicksearch-popup.cc
index 16b44c1..c1c8499 100644
--- a/src/gnome-cmd-quicksearch-popup.cc
+++ b/src/gnome-cmd-quicksearch-popup.cc
@@ -44,7 +44,7 @@ struct GnomeCmdQuicksearchPopupPrivate
 
 inline void focus_file (GnomeCmdQuicksearchPopup *popup, GnomeCmdFile *f)
 {
-    if (strcmp (f->info->name, "..") == 0)
+    if (f->is_dotdot)
         return;
 
     popup->priv->last_focused_file = f;
diff --git a/src/gnome-cmd-search-dialog.cc b/src/gnome-cmd-search-dialog.cc
index 0a079a8..68d2e83 100644
--- a/src/gnome-cmd-search-dialog.cc
+++ b/src/gnome-cmd-search-dialog.cc
@@ -294,8 +294,7 @@ static void search_dir_r (GnomeCmdDir *dir, SearchData *data)
         if (GNOME_CMD_IS_DIR (f) && data->recurse)
         {
             // we don't want to go backwards or follow symlinks
-            if (strcmp (f->info->name, ".") != 0 &&
-                strcmp (f->info->name, "..") != 0 &&
+            if (!f->is_dotdot && strcmp (f->info->name, ".") != 0 &&
                 !GNOME_VFS_FILE_INFO_SYMLINK (f->info))
             {
                 GnomeCmdDir *new_dir = GNOME_CMD_DIR (f);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]