[svn-commits] dlee: branch dlee/stasis-forward-optimization r399993 - /team/dlee/stasis-for...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Sep 27 13:54:23 CDT 2013
Author: dlee
Date: Fri Sep 27 13:54:22 2013
New Revision: 399993
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399993
Log:
Review feedback:
* ast_vector_remove_unordered returns the element removed
* Introduced ast_vector_remove_cmp_unordered
Modified:
team/dlee/stasis-forward-optimization/include/asterisk/vector.h
Modified: team/dlee/stasis-forward-optimization/include/asterisk/vector.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-forward-optimization/include/asterisk/vector.h?view=diff&rev=399993&r1=399992&r2=399993
==============================================================================
--- team/dlee/stasis-forward-optimization/include/asterisk/vector.h (original)
+++ team/dlee/stasis-forward-optimization/include/asterisk/vector.h Fri Sep 27 13:54:22 2013
@@ -119,12 +119,43 @@
*
* \param vec Vector to remove from.
* \param idx Index of the element to remove.
+ * \return The element that was removed.
*/
-#define ast_vector_remove_unordered(vec, idx) do { \
+#define ast_vector_remove_unordered(vec, idx) ({ \
+ typeof((vec).elems[0]) res; \
size_t __idx = (idx); \
ast_assert(__idx < (vec).current); \
+ res = (vec).elems[__idx]; \
(vec).elems[__idx] = (vec).elems[--(vec).current]; \
-} while (0)
+ res; \
+})
+
+
+/*!
+ * \brief Remove an element from a vector that matches the given comparison
+ *
+ * \param vec Vector to remove from.
+ * \param value Value to pass into comparator.
+ * \param cmp Comparator function/macros (called as \c cmp(elem, value))
+ * \return 0 if element was removed.
+ * \return Non-zero if element was not in the vector.
+ */
+#define ast_vector_remove_cmp_unordered(vec, value, cmp) ({ \
+ int res = -1; \
+ size_t idx; \
+ typeof(value) __value = (value); \
+ for (idx = 0; idx < (vec).current; ++idx) { \
+ if (cmp(__value, (vec).elems[idx])) { \
+ ast_vector_remove_unordered((vec), idx); \
+ res = 0; \
+ break; \
+ } \
+ } \
+ res; \
+})
+
+/*! \brief Default comparator for ast_vector_remove_elem_unordered() */
+#define AST_VECTOR_DEFAULT_CMP(a, b) ((a) == (b))
/*!
* \brief Remove an element from a vector.
@@ -134,20 +165,10 @@
* \return 0 if element was removed.
* \return Non-zero if element was not in the vector.
*/
-#define ast_vector_remove_elem_unordered(vec, elem) ({ \
- int res = -1; \
- size_t idx; \
- typeof(elem) __elem = (elem); \
- for (idx = 0; idx < (vec).current; ++idx) { \
- if (__elem == (vec).elems[idx]) { \
- (vec).elems[idx] = (vec).elems[--(vec).current]; \
- res = 0; \
- break; \
- } \
- } \
- res; \
+#define ast_vector_remove_elem_unordered(vec, elem) ({ \
+ ast_vector_remove_cmp_unordered((vec), (elem), \
+ AST_VECTOR_DEFAULT_CMP); \
})
-
/*!
* \brief Get the number of elements in a vector.
More information about the svn-commits
mailing list