gnome-commander r2422 - in trunk: . src



Author: epiotr
Date: Tue Jan 13 19:28:28 2009
New Revision: 2422
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2422&view=rev

Log:
Tweaks for making startup faster

Modified:
   trunk/ChangeLog
   trunk/src/gnome-cmd-file.cc
   trunk/src/owner.cc
   trunk/src/owner.h

Modified: trunk/src/gnome-cmd-file.cc
==============================================================================
--- trunk/src/gnome-cmd-file.cc	(original)
+++ trunk/src/gnome-cmd-file.cc	Tue Jan 13 19:28:28 2009
@@ -473,10 +473,7 @@
     g_return_val_if_fail (file->info != NULL, NULL);
 
     if (GNOME_VFS_FILE_INFO_LOCAL (file->info))
-    {
-        user_t *owner = OWNER_get_user_by_uid (file->info->uid);
-        return owner->name;
-    }
+        return OWNER_get_name_by_uid (file->info->uid);
     else
     {
         static gchar owner_str[MAX_OWNER_LENGTH];
@@ -492,10 +489,7 @@
     g_return_val_if_fail (file->info != NULL, NULL);
 
     if (GNOME_VFS_FILE_INFO_LOCAL (file->info))
-    {
-        group_t *group = OWNER_get_group_by_gid (file->info->gid);
-        return group->name;
-    }
+        return OWNER_get_name_by_gid (file->info->gid);
     else
     {
         static gchar group_str[MAX_GROUP_LENGTH];

Modified: trunk/src/owner.cc
==============================================================================
--- trunk/src/owner.cc	(original)
+++ trunk/src/owner.cc	Tue Jan 13 19:28:28 2009
@@ -42,7 +42,7 @@
 }
 
 
-static user_t *create_user (struct passwd *pw, gboolean zombie)
+inline user_t *create_user (struct passwd *pw, gboolean zombie)
 {
     if (pw)
     {
@@ -56,12 +56,9 @@
 
         user->zombie =   zombie;
         user->name =     g_strdup (pw->pw_name);
-        user->passwd =   g_strdup (pw->pw_passwd);
         user->uid =      pw->pw_uid;
         user->gid =      pw->pw_gid;
         user->realname = g_strdup (pw->pw_gecos);
-        user->homedir =  g_strdup (pw->pw_dir);
-        user->shell =    g_strdup (pw->pw_shell);
         user->groups =   NULL; // filled in later when going through the group members
 
         return user;
@@ -84,7 +81,6 @@
 
         group->zombie =  zombie;
         group->name =    g_strdup (gr->gr_name);
-        group->passwd =  g_strdup (gr->gr_passwd);
         group->gid =     gr->gr_gid;
         group->members = NULL;
 
@@ -110,34 +106,30 @@
 }
 
 
-static void free_user (user_t *user)
+inline void free_user (user_t *user)
 {
     g_free (user->name);
-    g_free (user->passwd);
     g_free (user->realname);
-    g_free (user->homedir);
-    g_free (user->shell);
     g_free (user);
 }
 
 
-static void free_group (group_t *group)
+inline void free_group (group_t *group)
 {
     g_free (group->name);
-    g_free (group->passwd);
     g_list_free (group->members);
     g_free (group);
 }
 
 
-static void lookup_all_users ()
+inline void lookup_all_users ()
 {
     struct passwd *pw;
 
     setpwent ();
 
     while ((pw = getpwent ()) != NULL)
-        all_users = g_list_append (all_users, create_user (pw, FALSE));
+        all_users = g_list_prepend (all_users, create_user (pw, FALSE));
 
     endpwent ();
 
@@ -145,14 +137,14 @@
 }
 
 
-static void lookup_all_groups ()
+inline void lookup_all_groups ()
 {
     struct group *gr;
 
     setgrent ();
 
     while ((gr = getgrent ()) != NULL)
-        all_groups = g_list_append (all_groups, create_group (gr, FALSE));
+        all_groups = g_list_prepend (all_groups, create_group (gr, FALSE));
 
     endgrent ();
 
@@ -160,24 +152,25 @@
 }
 
 
-static void check_user_default_groups ()
+inline void check_user_default_groups ()
 {
     user_t *user;
     group_t *group;
-    GList *utmp, *gtmp;
 
-
-    for (utmp=all_users; utmp; utmp=utmp->next)
+    for (GList *utmp=all_users; utmp; utmp=utmp->next)
     {
         group_t *def_group = NULL;
         user = (user_t *) utmp->data;
 
-        for (gtmp=user->groups; gtmp; gtmp=gtmp->next)
+        for (GList *gtmp=user->groups; gtmp; gtmp=gtmp->next)
         {
             group = (group_t *) gtmp->data;
 
             if (group->gid == user->gid)
+            {
                 def_group = group;
+                break;
+            }
         }
 
         if (!def_group)
@@ -301,35 +294,29 @@
 void OWNER_free ()
 {
 
-    GList *groups;
-    GList *users;
-
     /* free users */
-    for (users = all_users; users; users = users->next)
+    for (GList *users=all_users; users; users=users->next)
     {
         user_t *user = (user_t *) users->data;
         free_user (user);
     }
 
     /* free groups */
-    for (groups = all_groups; groups; groups = groups->next)
+    for (GList *groups=all_groups; groups; groups=groups->next)
     {
         group_t *group = (group_t *) groups->data;
         free_group (group);
     }
 
-    g_list_free (users);
-    g_list_free (groups);
+    g_list_free (all_users);
+    g_list_free (all_groups);
 }
 
 
 user_t *OWNER_get_program_user ()
 {
-    const char *name;
-    user_t *user;
-
-    name = g_get_user_name ();
-    user = OWNER_get_user_by_name (name);
+    const char *name = g_get_user_name ();
+    user_t *user = OWNER_get_user_by_name (name);
 
     g_assert (user);
 
@@ -347,41 +334,3 @@
 {
     return all_groups;
 }
-
-
-const gchar *OWNER_get_name_by_uid (uid_t uid)
-{
-    user_t *user = OWNER_get_user_by_uid (uid);
-    if (!user)
-        return NULL;
-    return user->name;
-}
-
-
-const gchar *OWNER_get_name_by_gid (gid_t gid)
-{
-    group_t *group = OWNER_get_group_by_gid (gid);
-    if (!group)
-        return NULL;
-    return group->name;
-}
-
-
-uid_t OWNER_get_uid_by_name (const gchar *name)
-{
-    user_t *user = OWNER_get_user_by_name (name);
-    if (!user)
-        return -1;
-    return user->uid;
-}
-
-
-gid_t OWNER_get_gid_by_name (const gchar *name)
-{
-    group_t *group = OWNER_get_group_by_name (name);
-    if (!group)
-        return -1;
-    return group->gid;
-}
-
-

Modified: trunk/src/owner.h
==============================================================================
--- trunk/src/owner.h	(original)
+++ trunk/src/owner.h	Tue Jan 13 19:28:28 2009
@@ -24,29 +24,24 @@
 #include <grp.h>
 #include <pwd.h>
 
-typedef struct
+struct group_t
 {
-    gboolean zombie;    /* The gid of this group doesnt match any group in the system. */
     char *name;
-    char *passwd;
     gid_t gid;
-    GList *members;     /* stores the  members as char *strings */
-} group_t;
+    GList *members;     // stores the members as char *strings
+    gboolean zombie;    // The gid of this group doesn't match any group in the system
+};
 
-
-typedef struct
+struct user_t
 {
-    gboolean zombie;    /* The uid of this user doesnt match any user in the system. */
     char *name;
-    char *passwd;
     uid_t uid;
     gid_t gid;
     group_t *group;
     char *realname;
-    char *homedir;
-    char *shell;
     GList *groups;
-} user_t;
+    gboolean zombie;    // The uid of this user doesn't match any user in the system
+};
 
 void OWNER_init ();
 void OWNER_free ();
@@ -57,9 +52,36 @@
 group_t *OWNER_get_group_by_name (const char *name);
 GList *OWNER_get_all_users ();
 GList *OWNER_get_all_groups ();
-const gchar *OWNER_get_name_by_uid (uid_t uid);
-const gchar *OWNER_get_name_by_gid (gid_t gid);
-uid_t OWNER_get_uid_by_name (const gchar *name);
-gid_t OWNER_get_gid_by_name (const gchar *name);
+
+inline const gchar *OWNER_get_name_by_uid (uid_t uid)
+{
+    user_t *user = OWNER_get_user_by_uid (uid);
+
+    return user ? user->name : NULL;
+}
+
+
+inline const gchar *OWNER_get_name_by_gid (gid_t gid)
+{
+    group_t *group = OWNER_get_group_by_gid (gid);
+
+    return group ? group->name : NULL;
+}
+
+
+inline uid_t OWNER_get_uid_by_name (const gchar *name)
+{
+    user_t *user = OWNER_get_user_by_name (name);
+
+    return user ? user->uid : -1;
+}
+
+
+inline gid_t OWNER_get_gid_by_name (const gchar *name)
+{
+    group_t *group = OWNER_get_group_by_name (name);
+
+    return group ? group->gid : -1;
+}
 
 #endif // __OWNER_H__



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