Mercurial > pidgin
comparison src/cmds.c @ 9343:5f6ba17ef9f5
[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.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Tue, 22 Jun 2004 05:03:24 +0000 |
parents | 3e2ea5b69605 |
children | 796f510a6e19 |
comparison
equal
deleted
inserted
replaced
9342:33693eea90d7 | 9343:5f6ba17ef9f5 |
---|---|
48 else if (a->id < b->id) | 48 else if (a->id < b->id) |
49 return 1; | 49 return 1; |
50 else return 0; | 50 else return 0; |
51 } | 51 } |
52 | 52 |
53 GaimCmdId *gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f, | 53 GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f, |
54 const gchar *prpl_id, GaimCmdFunc func, const gchar *helpstr) | 54 const gchar *prpl_id, GaimCmdFunc func, const gchar *helpstr) |
55 { | 55 { |
56 GaimCmdId *id; | 56 GaimCmdId id; |
57 GaimCmd *c; | 57 GaimCmd *c; |
58 | 58 |
59 g_return_val_if_fail(cmd != NULL && *cmd != '\0', NULL); | 59 g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0); |
60 g_return_val_if_fail(args != NULL, NULL); | 60 g_return_val_if_fail(args != NULL, 0); |
61 g_return_val_if_fail(func != NULL, NULL); | 61 g_return_val_if_fail(func != NULL, 0); |
62 | 62 |
63 id = g_new(GaimCmdId, 1); | 63 id = next_id++; |
64 *id = next_id++; | |
65 | 64 |
66 c = g_new0(GaimCmd, 1); | 65 c = g_new0(GaimCmd, 1); |
67 c->id = *id; | 66 c->id = id; |
68 c->cmd = g_strdup(cmd); | 67 c->cmd = g_strdup(cmd); |
69 c->args = g_strdup(args); | 68 c->args = g_strdup(args); |
70 c->priority = p; | 69 c->priority = p; |
71 c->flags = f; | 70 c->flags = f; |
72 c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL; | 71 c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL; |
88 g_free(c->help); | 87 g_free(c->help); |
89 | 88 |
90 g_free(c); | 89 g_free(c); |
91 } | 90 } |
92 | 91 |
93 void gaim_cmd_unregister(GaimCmdId *id) | 92 void gaim_cmd_unregister(GaimCmdId id) |
94 { | 93 { |
95 GaimCmd *c; | 94 GaimCmd *c; |
96 GList *l; | 95 GList *l; |
97 | 96 |
98 for (l = cmds; l; l = l->next) { | 97 for (l = cmds; l; l = l->next) { |
99 c = l->data; | 98 c = l->data; |
100 | 99 |
101 if (c->id == *id) { | 100 if (c->id == id) { |
102 cmds = g_list_remove(cmds, c); | 101 cmds = g_list_remove(cmds, c); |
103 gaim_cmd_free(c); | 102 gaim_cmd_free(c); |
104 g_free(id); | |
105 return; | 103 return; |
106 } | 104 } |
107 } | 105 } |
108 } | 106 } |
109 | 107 |