[Bf-blender-cvs] [ed26d9d] master: BLI_array: utility function for searching an array
Campbell Barton
noreply at git.blender.org
Sun Aug 17 08:02:54 CEST 2014
Commit: ed26d9dd90cd67c0ee4d88e1b4da9f2e6ac963d0
Author: Campbell Barton
Date: Sun Aug 17 15:56:44 2014 +1000
Branches: master
https://developer.blender.org/rBed26d9dd90cd67c0ee4d88e1b4da9f2e6ac963d0
BLI_array: utility function for searching an array
===================================================================
M source/blender/blenlib/BLI_array.h
M source/blender/blenlib/intern/BLI_array.c
===================================================================
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h
index 0cd6498..3a9d013 100644
--- a/source/blender/blenlib/BLI_array.h
+++ b/source/blender/blenlib/BLI_array.h
@@ -181,5 +181,8 @@ void _bli_array_wrap(void *arr, unsigned int arr_len, size_t arr_stride, int dir
#define BLI_array_wrap(arr, arr_len, dir) \
_bli_array_wrap(arr, arr_len, sizeof(*(arr)), dir)
+int _bli_array_findindex(const void *arr, unsigned int arr_len, size_t arr_stride, const void *p);
+#define BLI_array_findindex(arr, arr_len, p) \
+ _bli_array_findindex(arr, arr_len, sizeof(*(arr)), p)
#endif /* __BLI_ARRAY_H__ */
diff --git a/source/blender/blenlib/intern/BLI_array.c b/source/blender/blenlib/intern/BLI_array.c
index 21d7a5a..da2eef8 100644
--- a/source/blender/blenlib/intern/BLI_array.c
+++ b/source/blender/blenlib/intern/BLI_array.c
@@ -137,3 +137,18 @@ void _bli_array_wrap(void *arr_v, unsigned int arr_len, size_t arr_stride, int d
BLI_assert(0);
}
}
+
+/**
+ * \note Not efficient, use for error checks/asserts.
+ */
+int _bli_array_findindex(const void *arr, unsigned int arr_len, size_t arr_stride, const void *p)
+{
+ const char *arr_step = (const char *)arr;
+ unsigned int i;
+ for (i = 0; i < arr_len; i++, arr_step += arr_stride) {
+ if (memcmp(arr_step, p, arr_stride) == 0) {
+ return (int)i;
+ }
+ }
+ return -1;
+}
More information about the Bf-blender-cvs
mailing list