dbus-message cleanup ...

Michael Meeks michael@ximian.com
Fri, 05 Mar 2004 10:30:29 +0000


--=-v9WDD86tkA11vx+ITKGK
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi there,

	Just reading the code, and I noticed that this will most likely
generate something larger / slower than is absolutely necessary;
attached patch also reduces line-count.

	May I commit ?

	Thanks,

		Michael.

-- 
 michael@ximian.com  <><, Pseudo Engineer, itinerant idiot

--=-v9WDD86tkA11vx+ITKGK
Content-Disposition: attachment; filename=dbus-msg.diff
Content-Type: text/x-patch; name=dbus-msg.diff; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: dbus/dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.118
diff -u -p -u -r1.118 dbus-message.c
--- a/dbus/dbus-message.c	17 Dec 2003 12:24:33 -0000	1.118
+++ b/dbus/dbus-message.c	5 Mar 2004 10:33:00 -0000
@@ -2260,6 +2260,7 @@ dbus_message_iter_get_args_valist (DBusM
 	  {
 	    void **data;
 	    int *len, type;
+	    dbus_bool_t err = FALSE;
  
 	    type = va_arg (var_args, int);
 	    data = va_arg (var_args, void *);
@@ -2281,62 +2282,30 @@ dbus_message_iter_get_args_valist (DBusM
 	    switch (type)
 	      {
 	      case DBUS_TYPE_BYTE:
-		if (!dbus_message_iter_get_byte_array (iter, (unsigned char **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_byte_array (iter, (unsigned char **)data, len);
 		break;
 	      case DBUS_TYPE_BOOLEAN:
-		if (!dbus_message_iter_get_boolean_array (iter, (unsigned char **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_boolean_array (iter, (unsigned char **)data, len);
 		break;
 	      case DBUS_TYPE_INT32:
-		if (!dbus_message_iter_get_int32_array (iter, (dbus_int32_t **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_int32_array (iter, (dbus_int32_t **)data, len);
 		break;
 	      case DBUS_TYPE_UINT32:
-		if (!dbus_message_iter_get_uint32_array (iter, (dbus_uint32_t **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err =!dbus_message_iter_get_uint32_array (iter, (dbus_uint32_t **)data, len);
 		break;
 #ifdef DBUS_HAVE_INT64
               case DBUS_TYPE_INT64:
-		if (!dbus_message_iter_get_int64_array (iter, (dbus_int64_t **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_int64_array (iter, (dbus_int64_t **)data, len);
 		break;
 	      case DBUS_TYPE_UINT64:
-		if (!dbus_message_iter_get_uint64_array (iter, (dbus_uint64_t **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_uint64_array (iter, (dbus_uint64_t **)data, len);
 		break;
 #endif /* DBUS_HAVE_INT64 */
 	      case DBUS_TYPE_DOUBLE:
-		if (!dbus_message_iter_get_double_array (iter, (double **)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_double_array (iter, (double **)data, len);
 		break;
 	      case DBUS_TYPE_STRING:
-		if (!dbus_message_iter_get_string_array (iter, (char ***)data, len))
-		  {
-		    dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-		    goto out;
-		  }
+		err = !dbus_message_iter_get_string_array (iter, (char ***)data, len);
 		break;
 	      case DBUS_TYPE_NIL:
 	      case DBUS_TYPE_ARRAY:
@@ -2350,6 +2319,11 @@ dbus_message_iter_get_args_valist (DBusM
 		dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED, NULL);
 		goto out;
 	      }
+	    if (err)
+	      {
+	        dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+		goto out;
+	      }
 	  }
 	  break;
 	case DBUS_TYPE_DICT:

--=-v9WDD86tkA11vx+ITKGK--