summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Piechotka <uzytkownik2@gmail.com>2013-07-30 12:56:31 +0200
committerMaciej Piechotka <uzytkownik2@gmail.com>2013-07-30 12:57:16 +0200
commitf20cdb80cabab7af08c5620d371fcdd9cbc59de2 (patch)
tree7b8d30f16e65f3201d87de6a7894450a7d039a79
parent13f8f10f727aca660dbbaad7ca1bd00e8d0a7ae1 (diff)
downloadlibgee-f20cdb80cabab7af08c5620d371fcdd9cbc59de2.tar.gz
Avoid unnecessary allocation for destroy notify
-rw-r--r--gee/Makefile.am1
-rw-r--r--gee/hazardpointer.vala14
-rw-r--r--utils/free.h30
-rw-r--r--utils/geeutils.vapi4
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> ();
+ }
}
}