dee

Merge lp:~mhr3/dee/gi-modeliter into lp:dee

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 341
Merged at revision: 340
Proposed branch: lp:~mhr3/dee/gi-modeliter
Merge into: lp:dee
Diff against target: 161 lines (+78/-6)
3 files modified
src/dee-model.c (+38/-6)
src/dee-model.h (+4/-0)
tests/test-model-rows.c (+36/-0)
To merge this branch: bzr merge lp:~mhr3/dee/gi-modeliter
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+90306@code.launchpad.net

Description of the change

Makes DeeModelIter usable from introspected languages by registering it as a boxed GType.

To post a comment you must log in.
lp:~mhr3/dee/gi-modeliter updated
340. By Michal Hruby

Make DeeModelIter usable from introspected languages

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

16 + /* FIXME: this implementation will work fine with DeeSequenceModel, but what
17 + * about others? */

This is not an issue. It's implicit in the DeeModel interface that iters are stable (that is you can keep them around and pass like pointers).

What I am mostly concerned about for this branch is performance. The signals will now do lookup in the Boxed type tree, so it might be a slow-down.

Before I can approve can you:

a) post benchmarks from before/after
b) add some tests for the boxing logic

review: Needs Fixing
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Ok, I can the benchmarks myself. Looks like the boxing is a non-issue:

TRUNK:
=== SequenceModel.append ===
Runs : 100
Total runtime : 2.262057s
Avg. runtime : 0.022621s
Std. deviation : 0.001089s
Accuracy : 95.185140% [good]

=== SequenceModel.prepend ===
Runs : 100
Total runtime : 2.128361s
Avg. runtime : 0.021284s
Std. deviation : 0.000753s
Accuracy : 96.459987% [good]

THIS BRANCH:
=== SequenceModel.append ===
Runs : 100
Total runtime : 2.286914s
Avg. runtime : 0.022869s
Std. deviation : 0.001062s
Accuracy : 95.357487% [good]

=== SequenceModel.prepend ===
Runs : 100
Total runtime : 2.169105s
Avg. runtime : 0.021691s
Std. deviation : 0.000880s
Accuracy : 95.941740% [good]

lp:~mhr3/dee/gi-modeliter updated
341. By Michal Hruby

Add tests

Revision history for this message
Michal Hruby (mhr3) wrote :

Bump (tests were added).

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Perfect! Having signals and iters work over GI is just awesome :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dee-model.c'
2--- src/dee-model.c 2012-01-10 07:54:04 +0000
3+++ src/dee-model.c 2012-01-26 19:12:25 +0000
4@@ -141,6 +141,38 @@
5 GVariant **out_row_members,
6 va_list *args);
7
8+/*
9+ * We provide here a couple of DeeModelIter functions, so that they're usable
10+ * from introspected languages.
11+ */
12+
13+static gpointer
14+dee_model_iter_copy (gpointer boxed)
15+{
16+ /* FIXME: this implementation will work fine with DeeSequenceModel, but what
17+ * about others? */
18+ return boxed;
19+}
20+
21+static void
22+dee_model_iter_free (gpointer boxed)
23+{
24+}
25+
26+GType dee_model_iter_get_type (void)
27+{
28+ static GType dee_model_iter_type = 0;
29+
30+ if (dee_model_iter_type == 0)
31+ {
32+ dee_model_iter_type = g_boxed_type_register_static ("DeeModelIter",
33+ dee_model_iter_copy,
34+ dee_model_iter_free);
35+ }
36+
37+ return dee_model_iter_type;
38+}
39+
40 static void
41 dee_model_default_init (DeeModelInterface *klass)
42 {
43@@ -157,9 +189,9 @@
44 G_SIGNAL_RUN_LAST,
45 G_STRUCT_OFFSET (DeeModelIface,row_added),
46 NULL, NULL,
47- g_cclosure_marshal_VOID__POINTER,
48+ g_cclosure_marshal_VOID__BOXED,
49 G_TYPE_NONE, 1,
50- G_TYPE_POINTER);
51+ DEE_TYPE_MODEL_ITER);
52 /**
53 * DeeModel::row-removed:
54 * @self: the #DeeModel on which the signal is emitted
55@@ -174,9 +206,9 @@
56 G_SIGNAL_RUN_LAST,
57 G_STRUCT_OFFSET (DeeModelIface,row_removed),
58 NULL, NULL,
59- g_cclosure_marshal_VOID__POINTER,
60+ g_cclosure_marshal_VOID__BOXED,
61 G_TYPE_NONE, 1,
62- G_TYPE_POINTER);
63+ DEE_TYPE_MODEL_ITER);
64 /**
65 * DeeModel::row-changed:
66 * @self: the #DeeModel on which the signal is emitted
67@@ -190,9 +222,9 @@
68 G_SIGNAL_RUN_LAST,
69 G_STRUCT_OFFSET (DeeModelIface,row_changed),
70 NULL, NULL,
71- g_cclosure_marshal_VOID__POINTER,
72+ g_cclosure_marshal_VOID__BOXED,
73 G_TYPE_NONE, 1,
74- G_TYPE_POINTER);
75+ DEE_TYPE_MODEL_ITER);
76 }
77
78 /**
79
80=== modified file 'src/dee-model.h'
81--- src/dee-model.h 2012-01-10 07:54:04 +0000
82+++ src/dee-model.h 2012-01-26 19:12:25 +0000
83@@ -30,6 +30,8 @@
84
85 G_BEGIN_DECLS
86
87+#define DEE_TYPE_MODEL_ITER (dee_model_iter_get_type ())
88+
89 #define DEE_TYPE_MODEL (dee_model_get_type ())
90
91 #define DEE_MODEL(obj) \
92@@ -225,6 +227,8 @@
93 void (*_dee_model_8) (void);
94 };
95
96+GType dee_model_iter_get_type (void);
97+
98 /**
99 * dee_model_get_type:
100 *
101
102=== modified file 'tests/test-model-rows.c'
103--- tests/test-model-rows.c 2012-01-09 11:17:10 +0000
104+++ tests/test-model-rows.c 2012-01-26 19:12:25 +0000
105@@ -48,13 +48,22 @@
106 static void test_illegal_access (RowsFixture *fix, gconstpointer data);
107 static void test_sorted (RowsFixture *fix, gconstpointer data);
108
109+static void test_model_iter_copy (RowsFixture *fix, gconstpointer data);
110+static void test_model_iter_free (RowsFixture *fix, gconstpointer data);
111+
112 void
113 test_model_rows_create_suite (void)
114 {
115+#define ITER_DOMAIN "/ModelIter/Boxing"
116 #define SEQ_DOMAIN "/Model/Sequence/Rows"
117 #define PROXY_DOMAIN "/Model/Proxy/Rows"
118 #define TXN_DOMAIN "/Model/Transaction/Rows"
119
120+ g_test_add (ITER_DOMAIN"/Copy", RowsFixture, 0,
121+ seq_rows_setup, test_model_iter_copy, seq_rows_teardown);
122+ g_test_add (ITER_DOMAIN"/Free", RowsFixture, 0,
123+ seq_rows_setup, test_model_iter_free, seq_rows_teardown);
124+
125 g_test_add (SEQ_DOMAIN"/Allocation", RowsFixture, 0,
126 seq_rows_setup, test_rows_allocation, seq_rows_teardown);
127 g_test_add (PROXY_DOMAIN"/Allocation", RowsFixture, 0,
128@@ -176,6 +185,33 @@
129 fix->model = NULL;
130 }
131
132+static void test_model_iter_copy (RowsFixture *fix, gconstpointer data)
133+{
134+ DeeModelIter *iter, *copied;
135+
136+ iter = dee_model_append (fix->model, 10, "Rooney");
137+
138+ copied = g_boxed_copy (DEE_TYPE_MODEL_ITER, iter);
139+
140+ g_assert (iter == copied);
141+}
142+
143+static void test_model_iter_free (RowsFixture *fix, gconstpointer data)
144+{
145+ DeeModelIter *iter;
146+ gint i;
147+
148+ iter = dee_model_append (fix->model, 10, "Rooney");
149+
150+ g_boxed_free (DEE_TYPE_MODEL_ITER, iter);
151+
152+ /* And since it's supposed to be a no-op we can do this */
153+ for (i = 0; i < 100; i++)
154+ g_boxed_free (DEE_TYPE_MODEL_ITER, iter);
155+
156+ /* Didn't crash? Good! */
157+}
158+
159 static void
160 test_rows_allocation (RowsFixture *fix, gconstpointer data)
161 {

Subscribers

People subscribed via source and target branches

to all changes: