[libgee] Avoid unnecessary allocation for destroy notify



commit f20cdb80cabab7af08c5620d371fcdd9cbc59de2
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Tue Jul 30 12:56:31 2013 +0200

    Avoid unnecessary allocation for destroy notify

 gee/Makefile.am        |    1 +
 gee/hazardpointer.vala |   14 ++------------
 utils/free.h           |   30 ++++++++++++++++++++++++++++++
 utils/geeutils.vapi    |    4 ++++
 4 files changed, 37 insertions(+), 12 deletions(-)
---
diff --git a/gee/Makefile.am b/gee/Makefile.am
index 0d6a065..7dcfada 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -78,6 +78,7 @@ libgee_0_8_la_SOURCES = \
        treeset.vala \
        unfolditerator.vala \
        ../utils/async.h \
+       ../utils/free.h \
        $(NULL)
 
 libgee_0_8_la_VALAFLAGS = \
diff --git a/gee/hazardpointer.vala b/gee/hazardpointer.vala
index 5c8f747..411aefd 100644
--- a/gee/hazardpointer.vala
+++ b/gee/hazardpointer.vala
@@ -165,7 +165,7 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
        public static void set_pointer<G> (G **aptr, owned G? new_ptr, size_t mask = 0, size_t new_mask = 0) {
                HazardPointer<G>? ptr = exchange_hazard_pointer<G> (aptr, new_ptr, mask, new_mask, null);
                if (ptr != null) {
-                       DestroyNotify<G> notify = get_destroy_notify<G> ();
+                       DestroyNotify notify = Utils.Free.get_destroy_notify<G> ();
                        ptr.release ((owned)notify);
                }
        }
@@ -202,7 +202,7 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
                void *old_rptr = (void *)((size_t)(old_ptr) | (mask & old_mask));
                bool success = AtomicPointer.compare_and_exchange((void **)aptr, old_rptr, new_rptr);
                if (success) {
-                       DestroyNotify<G> notify = get_destroy_notify<G> ();
+                       DestroyNotify notify = Utils.Free.get_destroy_notify<G> ();
                        if (old_ptr != null) {
                                Context.get_current_context ()->release_ptr (old_ptr, (owned)notify);
                        }
@@ -430,8 +430,6 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
                }
        }
 
-       public delegate void DestroyNotify (void *ptr);
-
        /**
         * Release policy determines what happens with object freed by Policy.TRY_RELEASE
         * and Policy.RELEASE.
@@ -698,14 +696,6 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
 
        internal static ArrayList<FreeNode *> _global_to_free;
 
-       internal static DestroyNotify get_destroy_notify<G> () {
-               return (ptr) => {
-                       G *gptr = ptr;
-                       G obj = (owned)gptr;
-                       obj = null;
-               };
-       }
-
        [Compact]
        internal class FreeNode {
                public void *pointer;
diff --git a/utils/free.h b/utils/free.h
new file mode 100644
index 0000000..85457e6
--- /dev/null
+++ b/utils/free.h
@@ -0,0 +1,30 @@
+/* free.h
+ *
+ * Copyright (C) 2013  Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Maciej Piechotka <uzytkownik2 gmail com>
+ */
+#ifndef GEE_UTILS_ASYNC
+#define GEE_UTILS_ASYNC
+
+#include <glib.h>
+
+#define gee_utils_free_get_destroy_notify(type, dup, destroy) (destroy)
+
+#endif
+
diff --git a/utils/geeutils.vapi b/utils/geeutils.vapi
index 451d1e1..f7d5de6 100644
--- a/utils/geeutils.vapi
+++ b/utils/geeutils.vapi
@@ -4,5 +4,9 @@ namespace Gee {
                        [CCode (cheader_filename = "async.h")]
                        public async void yield_and_unlock (GLib.Mutex mutex);
                }
+               namespace Free {
+                       [CCode (cheader_filename = "free.h")]
+                       public GLib.DestroyNotify get_destroy_notify<G> ();
+               }
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]