summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMaciej Piechotka <uzytkownik2@gmail.com>2014-06-21 20:16:04 +0200
committerMaciej Piechotka <uzytkownik2@gmail.com>2014-06-22 16:15:59 +0200
commit08a45821599c8040948d938c3fcf50b334b40719 (patch)
tree253b2a1cfc01b129835210152958b2cccfde9790 /utils
parent5c756367f1ac77c8b450e55479462e1280e2d67c (diff)
downloadlibgee-08a45821599c8040948d938c3fcf50b334b40719.tar.gz
Conditionally assume in Gee.ArrayList and Gee.LinkedList
Diffstat (limited to 'utils')
-rw-r--r--utils/assume.h33
-rw-r--r--utils/geeutils.vapi4
2 files changed, 37 insertions, 0 deletions
diff --git a/utils/assume.h b/utils/assume.h
new file mode 100644
index 0000000..35dff51
--- /dev/null
+++ b/utils/assume.h
@@ -0,0 +1,33 @@
+/* assume.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_ASSUME
+#define GEE_UTILS_ASSUME
+
+#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ >= 40500
+#define gee_utils_assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0)
+#elif defined(_MSC_VER)
+#define gee_utils_assume(cond) __assume(cond)
+#else
+#define gee_utils_assume(cond) NULL
+#endif
+
+#endif
diff --git a/utils/geeutils.vapi b/utils/geeutils.vapi
index b25a79e..7b1472d 100644
--- a/utils/geeutils.vapi
+++ b/utils/geeutils.vapi
@@ -1,5 +1,9 @@
namespace Gee {
namespace Utils {
+ namespace Assume {
+ [CCode (cheader_filename = "assume.h", cname = "gee_utils_assume")]
+ public void assume(bool cond);
+ }
namespace Async {
[CCode (cheader_filename = "async.h")]
public async void yield_and_unlock (GLib.Mutex mutex);