nxt_array.c (146:24354fd871d5) nxt_array.c (1489:4a3ec07f4b19)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 95 unchanged lines hidden (view full) ---

104 last = nxt_array_last(array);
105
106 if (elt != last) {
107 nxt_memcpy(elt, last, array->size);
108 }
109
110 array->nelts--;
111}
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 95 unchanged lines hidden (view full) ---

104 last = nxt_array_last(array);
105
106 if (elt != last) {
107 nxt_memcpy(elt, last, array->size);
108 }
109
110 array->nelts--;
111}
112
113
114nxt_array_t *
115nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, nxt_array_t *src)
116{
117 void *data;
118 uint32_t i, size;
119
120 size = src->size;
121
122 if (dst == NULL) {
123 dst = nxt_array_create(mp, src->nelts, size);
124 if (nxt_slow_path(dst == NULL)) {
125 return NULL;
126 }
127 }
128
129 nxt_assert(size == dst->size);
130
131 if (dst->nalloc >= src->nelts) {
132 nxt_memcpy(dst->elts, src->elts, src->nelts * size);
133
134 } else {
135 nxt_memcpy(dst->elts, src->elts, dst->nelts * size);
136
137 for (i = dst->nelts; i < src->nelts; i++) {
138 data = nxt_array_add(dst);
139 if (nxt_slow_path(data == NULL)) {
140 return NULL;
141 }
142
143 nxt_memcpy(data, src->elts + (i * size), size);
144 }
145 }
146
147 dst->nelts = src->nelts;
148
149 return dst;
150}