summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_array.c
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2020-05-28 18:13:06 +0300
committerAndrei Belov <defan@nginx.com>2020-05-28 18:13:06 +0300
commit733c14e991d6b2d5bdae5202ae9f090d022bc956 (patch)
tree120562db5d30e5f4f51d001397f765f5cebab999 /src/nxt_array.c
parent6a8d4571d7fc89a951b4da80c39a93fcaa634406 (diff)
parent9d8e476c4e3695019b0a1fe3696d3411a8393de6 (diff)
downloadunit-733c14e991d6b2d5bdae5202ae9f090d022bc956.tar.gz
unit-733c14e991d6b2d5bdae5202ae9f090d022bc956.tar.bz2
Merged with the default branch.
Diffstat (limited to 'src/nxt_array.c')
-rw-r--r--src/nxt_array.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nxt_array.c b/src/nxt_array.c
index 82019f92..6fe9ad6a 100644
--- a/src/nxt_array.c
+++ b/src/nxt_array.c
@@ -109,3 +109,42 @@ nxt_array_remove(nxt_array_t *array, void *elt)
array->nelts--;
}
+
+
+nxt_array_t *
+nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, nxt_array_t *src)
+{
+ void *data;
+ uint32_t i, size;
+
+ size = src->size;
+
+ if (dst == NULL) {
+ dst = nxt_array_create(mp, src->nelts, size);
+ if (nxt_slow_path(dst == NULL)) {
+ return NULL;
+ }
+ }
+
+ nxt_assert(size == dst->size);
+
+ if (dst->nalloc >= src->nelts) {
+ nxt_memcpy(dst->elts, src->elts, src->nelts * size);
+
+ } else {
+ nxt_memcpy(dst->elts, src->elts, dst->nelts * size);
+
+ for (i = dst->nelts; i < src->nelts; i++) {
+ data = nxt_array_add(dst);
+ if (nxt_slow_path(data == NULL)) {
+ return NULL;
+ }
+
+ nxt_memcpy(data, src->elts + (i * size), size);
+ }
+ }
+
+ dst->nelts = src->nelts;
+
+ return dst;
+}