[pygobject: 1/2] to-py-struct: don't copy the boxed if we are the sole owner of the wrapper
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject: 1/2] to-py-struct: don't copy the boxed if we are the sole owner of the wrapper
- Date: Thu, 1 Feb 2018 08:25:17 +0000 (UTC)
commit a4a68b3c7a4bb64c71e1bdbe52ede109b6bcd0bb
Author: Christoph Reiter <reiter christoph gmail com>
Date: Tue Jan 30 16:39:18 2018 +0100
to-py-struct: don't copy the boxed if we are the sole owner of the wrapper
In commit 7ed8191818733b9130bce84f78 things were changed to copy the
wrapped boxed after the Python function returned. In case the wrapper
is only used during the call there is no need to copy the boxed
as the wrapper will be freed anyway.
Add a special case and don't copy the boxed in case the refcount at
cleanup is only 1. This should speed up the common case.
thanks to @mathieudu for suggesting this
gi/pygi-struct-marshal.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gi/pygi-struct-marshal.c b/gi/pygi-struct-marshal.c
index 44797e75..48ed7445 100644
--- a/gi/pygi-struct-marshal.c
+++ b/gi/pygi-struct-marshal.c
@@ -475,8 +475,15 @@ arg_boxed_to_py_cleanup (PyGIInvokeState *state,
gpointer data,
gboolean was_processed)
{
- if (arg_cache->transfer == GI_TRANSFER_NOTHING)
- _pygi_boxed_copy_in_place ((PyGIBoxed *) cleanup_data);
+ PyGIBoxed *boxed;
+
+ if (arg_cache->transfer == GI_TRANSFER_NOTHING) {
+ boxed = (PyGIBoxed *) cleanup_data;
+ /* If we are the sole owner of the wrapper it will be freed after this
+ * anyway, so no need to copy the wrapped boxed. */
+ if (Py_REFCNT (boxed) > 1)
+ _pygi_boxed_copy_in_place (boxed);
+ }
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]