[gaim-migrate @ 10151]

Tue, 22 Jun 2004 05:03:24 +0000

author
Tim Ringenbach <marv@pidgin.im>
date
Tue, 22 Jun 2004 05:03:24 +0000
changeset 9343
f08f32e6f1a7
parent 9342
b0b10a2e182c
child 9344
46387a962d8c

[gaim-migrate @ 10151]
Changes things to return and accept GaimCmdId's instead of GaimCmdId*'s.
This saves 4 bytes of the heap per command, and makes grim's memory
profiler happy hopefully.
It probably angers plugin writers who started registering commands already.
Although maybe not since they probably don't have to change any code.

src/cmds.c file | annotate | diff | comparison | revisions
src/cmds.h file | annotate | diff | comparison | revisions
--- a/src/cmds.c	Tue Jun 22 04:21:54 2004 +0000
+++ b/src/cmds.c	Tue Jun 22 05:03:24 2004 +0000
@@ -50,21 +50,20 @@
 	else return 0;
 }
 
-GaimCmdId *gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f,
+GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f,
                              const gchar *prpl_id, GaimCmdFunc func, const gchar *helpstr)
 {
-	GaimCmdId *id;
+	GaimCmdId id;
 	GaimCmd *c;
 
-	g_return_val_if_fail(cmd != NULL && *cmd != '\0', NULL);
-	g_return_val_if_fail(args != NULL, NULL);
-	g_return_val_if_fail(func != NULL, NULL);
+	g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0);
+	g_return_val_if_fail(args != NULL, 0);
+	g_return_val_if_fail(func != NULL, 0);
 
-	id = g_new(GaimCmdId, 1);
-	*id = next_id++;
+	id = next_id++;
 
 	c = g_new0(GaimCmd, 1);
-	c->id = *id;
+	c->id = id;
 	c->cmd = g_strdup(cmd);
 	c->args = g_strdup(args);
 	c->priority = p;
@@ -90,7 +89,7 @@
 	g_free(c);
 }
 
-void gaim_cmd_unregister(GaimCmdId *id)
+void gaim_cmd_unregister(GaimCmdId id)
 {
 	GaimCmd *c;
 	GList *l;
@@ -98,10 +97,9 @@
 	for (l = cmds; l; l = l->next) {
 		c = l->data;
 
-		if (c->id == *id) {
+		if (c->id == id) {
 			cmds = g_list_remove(cmds, c);
 			gaim_cmd_free(c);
-			g_free(id);
 			return;
 		}
 	}
--- a/src/cmds.h	Tue Jun 22 04:21:54 2004 +0000
+++ b/src/cmds.h	Tue Jun 22 05:03:24 2004 +0000
@@ -116,10 +116,10 @@
  *                and any arguments it accpets (if it takes any arguments, otherwise no space), follow
  *                by a colon, two spaces, and a description of the command in sentence form. No slash
  *                before the command name.
- * @return A pointer to a GaimCmdId. This is only used for calling gaim_cmd_unregister, which frees it.
+ * @return A GaimCmdId. This is only used for calling gaim_cmd_unregister.
  *         Returns @c NULL on failure.
  */
-GaimCmdId *gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f,
+GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f,
                              const gchar *prpl_id, GaimCmdFunc func, const gchar *helpstr);
 
 /**
@@ -129,9 +129,9 @@
  * or something else that might go away. Normally this is called when the plugin
  * unloads itself.
  *
- * @param id The GaimCmdId to unregister. It is freed after being unregistered.
+ * @param id The GaimCmdId to unregister.
  */
-void gaim_cmd_unregister(GaimCmdId *id);
+void gaim_cmd_unregister(GaimCmdId id);
 
 /**
  * Do a command.

mercurial