[nautilus-actions] Optimize and comment status checking



commit 1f19d53c1cc77a45f85a74ae1aff500aadc02c37
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Oct 13 23:20:12 2009 +0200

    Optimize and comment status checking

 src/runtime/na-object-action.c  |    2 +-
 src/runtime/na-object-id.c      |    6 ++++++
 src/runtime/na-object-item.c    |    5 ++---
 src/runtime/na-object-menu.c    |    2 +-
 src/runtime/na-object-profile.c |   14 +++++---------
 src/runtime/na-object.c         |   22 ++++------------------
 6 files changed, 19 insertions(+), 32 deletions(-)
---
diff --git a/src/runtime/na-object-action.c b/src/runtime/na-object-action.c
index 5ce3d8d..b692d83 100644
--- a/src/runtime/na-object-action.c
+++ b/src/runtime/na-object-action.c
@@ -591,7 +591,7 @@ object_is_valid( const NAObject *action )
 		if( is_valid ){
 			valid_profiles = 0;
 			profiles = na_object_get_items_list( action );
-			for( ip = profiles ; ip ; ip = ip->next ){
+			for( ip = profiles ; ip && !valid_profiles ; ip = ip->next ){
 				if( na_iduplicable_is_valid( ip->data )){
 					valid_profiles += 1;
 				}
diff --git a/src/runtime/na-object-id.c b/src/runtime/na-object-id.c
index ffa6a68..cdab39d 100644
--- a/src/runtime/na-object-id.c
+++ b/src/runtime/na-object-id.c
@@ -463,6 +463,12 @@ object_copy( NAObject *target, const NAObject *source )
 	}
 }
 
+/*
+ * note that parent is not pertinent here, as two objects may be
+ * considered as equal even if they not have the same parent
+ * (and typically when we compare a duplicated object in the treeview
+ *  against its origin in the pivot !)
+ */
 static gboolean
 object_are_equal( const NAObject *a, const NAObject *b )
 {
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index b37aa30..4c0d478 100644
--- a/src/runtime/na-object-item.c
+++ b/src/runtime/na-object-item.c
@@ -818,9 +818,8 @@ object_copy( NAObject *target, const NAObject *source )
  * note 2: as a particular case, this function is not recursive
  * because the equality test will stop as soon as it fails, and we so
  * cannot be sure to even come here.
- *
- * The recursivity of na_object_check_status() is directly
- * dealt with by the main entry api function.
+ * So the recursivity of na_object_check_status() is directly dealt
+ * with by the main entry api function.
  *
  * More, the modification status of subitems doesn't have any
  * impact on this object itself, provided that subitems lists are
diff --git a/src/runtime/na-object-menu.c b/src/runtime/na-object-menu.c
index a262153..5216156 100644
--- a/src/runtime/na-object-menu.c
+++ b/src/runtime/na-object-menu.c
@@ -268,7 +268,7 @@ object_is_valid( const NAObject *menu )
 		if( is_valid ){
 			valid_subitems = 0;
 			subitems = na_object_get_items_list( menu );
-			for( ip = subitems ; ip ; ip = ip->next ){
+			for( ip = subitems ; ip && !valid_subitems ; ip = ip->next ){
 				if( na_iduplicable_is_valid( ip->data )){
 					valid_subitems += 1;
 				}
diff --git a/src/runtime/na-object-profile.c b/src/runtime/na-object-profile.c
index 08b12cc..7dadb16 100644
--- a/src/runtime/na-object-profile.c
+++ b/src/runtime/na-object-profile.c
@@ -1479,7 +1479,6 @@ object_are_equal( const NAObject *a, const NAObject *b )
 gboolean
 object_is_valid( const NAObject *profile )
 {
-	gchar *path, *parameters;
 	gboolean is_valid = TRUE;
 
 	g_return_val_if_fail( NA_IS_OBJECT_PROFILE( profile ), FALSE );
@@ -1487,18 +1486,15 @@ object_is_valid( const NAObject *profile )
 	if( !NA_OBJECT_PROFILE( profile )->private->dispose_has_run ){
 
 		if( is_valid ){
-			path = na_object_profile_get_path( NA_OBJECT_PROFILE( profile ));
-			parameters = na_object_profile_get_parameters( NA_OBJECT_PROFILE( profile ));
-
-			is_valid = ( path && g_utf8_strlen( path, -1 ) > 0 ) ||
-						( parameters && g_utf8_strlen( parameters, -1 ) > 0 );
+			is_valid =
+				( NA_OBJECT_PROFILE( profile )->private->path &&
+						g_utf8_strlen( NA_OBJECT_PROFILE( profile )->private->path, -1 ) > 0 ) ||
 
-			g_free( parameters );
-			g_free( path );
+				( NA_OBJECT_PROFILE( profile )->private->parameters &&
+						g_utf8_strlen( NA_OBJECT_PROFILE( profile )->private->parameters, -1 ) > 0 );
 		}
 	}
 
-	g_debug( "na_object_profile_object_is_valid: profile=%p, valid=%s", ( void * ) profile, is_valid ? "True":"False" );
 	return( is_valid );
 }
 
diff --git a/src/runtime/na-object.c b/src/runtime/na-object.c
index a5e3779..6776112 100644
--- a/src/runtime/na-object.c
+++ b/src/runtime/na-object.c
@@ -247,7 +247,8 @@ instance_finalize( GObject *object )
  *      +- valid_status = v_is_valid( object )             -> interface is_valid()
  *
  * Note that the recursivity is managed here, so that we can be sure
- * that edition status of childs is actually checked.
+ * that edition status of childs is actually checked before those of
+ * the parent.
  */
 void
 na_object_iduplicable_check_status( const NAObject *object )
@@ -696,21 +697,7 @@ copy_hierarchy( NAObject *target, const NAObject *source )
 static gboolean
 do_are_equal( const NAObject *a, const NAObject *b )
 {
-	gboolean are_equal;
-
-	/* as there is no data in NAObject, they are considered here as
-	 * equal is both null or both not null
-	 */
-	are_equal = ( a && b ) || ( !a && !b );
-
-#if NA_IDUPLICABLE_EDITION_STATUS_DEBUG
-	g_debug( "na_object_do_are_equal: a=%p (%s), b=%p (%s), are_equal=%s",
-			( void * ) a, G_OBJECT_TYPE_NAME( a ),
-			( void * ) b, G_OBJECT_TYPE_NAME( b ),
-			are_equal ? "True":"False" );
-#endif
-
-	return( are_equal );
+	return( TRUE );
 }
 
 static void
@@ -733,8 +720,7 @@ do_dump( const NAObject *object )
 static gboolean
 do_is_valid( const NAObject *object )
 {
-	/* as there is no data in NAObject, it is always valid */
-	return( object ? TRUE : FALSE );
+	return( TRUE );
 }
 
 static void



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