aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'android/utils/vector.c')
-rw-r--r--android/utils/vector.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/android/utils/vector.c b/android/utils/vector.c
new file mode 100644
index 0000000..9029d05
--- /dev/null
+++ b/android/utils/vector.c
@@ -0,0 +1,33 @@
+#include <android/utils/vector.h>
+#include <limits.h>
+
+extern void
+_avector_ensure( void** items, size_t itemSize, unsigned* pMaxItems, unsigned newCount )
+{
+ unsigned oldMax = *pMaxItems;
+
+ if (newCount > oldMax) {
+ unsigned newMax = oldMax;
+ unsigned bigMax = UINT_MAX / itemSize;
+
+ if (itemSize == 0) {
+ AASSERT_FAIL("trying to reallocate array of 0-size items (count=%d)\n", newCount);
+ }
+
+ if (newCount > bigMax) {
+ AASSERT_FAIL("trying to reallocate over-sized array of %d-bytes items (%d > %d)\n",
+ itemSize, newCount, bigMax);
+ }
+
+ while (newMax < newCount) {
+ unsigned newMax2 = newMax + (newMax >> 1) + 4;
+ if (newMax2 < newMax || newMax2 > bigMax)
+ newMax2 = bigMax;
+ newMax = newMax2;
+ }
+
+ *items = _android_array_realloc( *items, itemSize, newMax );
+ *pMaxItems = newMax;
+ }
+}
+