[gnome-commander/gcmd-1-2-8] GnomeCmdFile: minor speedups



commit 1647ba7cbb03c0872d7a30fb921ab18e8dac27c7
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 36c98b4..56f88ca 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 d99dbf2..bfe8fcf 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 cd16a26..b3fdcc9 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 aebe283..d1fb641 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -322,7 +322,7 @@ static void select_file (GnomeCmdFileList *fl, GnomeCmdFile *f)
     g_return_if_fail (f != NULL);
     g_return_if_fail (f->info != NULL);
 
-    if (strcmp (f->info->name, "..") == 0)
+    if (f->is_dotdot)
         return;
 
     gint row = fl->get_row_from_file(f);
@@ -789,10 +789,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)
@@ -809,10 +809,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)
@@ -839,10 +839,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)
@@ -872,10 +872,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];
@@ -895,10 +895,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];
@@ -917,10 +917,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];
@@ -939,10 +939,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];
@@ -961,10 +961,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];
@@ -1133,7 +1133,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)
                         {
@@ -2234,7 +2234,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 122b97a..52c0f36 100644
--- a/src/gnome-cmd-file-list.h
+++ b/src/gnome-cmd-file-list.h
@@ -224,7 +224,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 1e96575..0b2a707 100644
--- a/src/gnome-cmd-file-props-dialog.cc
+++ b/src/gnome-cmd-file-props-dialog.cc
@@ -655,7 +655,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 648a986..9ec1944 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -167,7 +167,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))
@@ -397,7 +397,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);
@@ -706,7 +706,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 102100f..f77c4f2 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 f558348..42ad86c 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 dd47bae..07c286f 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 e8ffc8f..ece211c 100644
--- a/src/gnome-cmd-search-dialog.cc
+++ b/src/gnome-cmd-search-dialog.cc
@@ -292,8 +292,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]