nxt_vector.c (0:a63ceefd6ab0) nxt_vector.c (98:4077decf847b)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8
9
10nxt_vector_t *
11nxt_vector_create(nxt_uint_t items, size_t item_size,
12 const nxt_mem_proto_t *proto, void *pool)
13{
14 nxt_vector_t *vector;
15
16 vector = proto->alloc(pool, sizeof(nxt_vector_t) + items * item_size);
17
18 if (nxt_fast_path(vector != NULL)) {
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8
9
10nxt_vector_t *
11nxt_vector_create(nxt_uint_t items, size_t item_size,
12 const nxt_mem_proto_t *proto, void *pool)
13{
14 nxt_vector_t *vector;
15
16 vector = proto->alloc(pool, sizeof(nxt_vector_t) + items * item_size);
17
18 if (nxt_fast_path(vector != NULL)) {
19 vector->start = (char *) vector + sizeof(nxt_vector_t);
19 vector->start = nxt_pointer_to(vector, sizeof(nxt_vector_t));
20 vector->items = 0;
21 vector->item_size = item_size;
22 vector->avalaible = items;
23 vector->type = NXT_VECTOR_EMBEDDED;
24 }
25
26 return vector;
27}

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

107 if (vector->type == NXT_VECTOR_EMBEDDED) {
108 vector->type = NXT_VECTOR_DESCRETE;
109
110 } else {
111 proto->free(pool, old);
112 }
113 }
114
20 vector->items = 0;
21 vector->item_size = item_size;
22 vector->avalaible = items;
23 vector->type = NXT_VECTOR_EMBEDDED;
24 }
25
26 return vector;
27}

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

107 if (vector->type == NXT_VECTOR_EMBEDDED) {
108 vector->type = NXT_VECTOR_DESCRETE;
109
110 } else {
111 proto->free(pool, old);
112 }
113 }
114
115 item = (char *) vector->start + vector->item_size * vector->items;
115 item = nxt_pointer_to(vector->start, vector->item_size * vector->items);
116
117 vector->items++;
118
119 return item;
120}
121
122
123void *

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

138
139void
140nxt_vector_remove(nxt_vector_t *vector, void *item)
141{
142 u_char *next, *last, *end;
143 uint32_t item_size;
144
145 item_size = vector->item_size;
116
117 vector->items++;
118
119 return item;
120}
121
122
123void *

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

138
139void
140nxt_vector_remove(nxt_vector_t *vector, void *item)
141{
142 u_char *next, *last, *end;
143 uint32_t item_size;
144
145 item_size = vector->item_size;
146 end = (u_char *) vector->start + item_size * vector->items;
146 end = nxt_pointer_to(vector->start, item_size * vector->items);
147 last = end - item_size;
148
149 if (item != last) {
147 last = end - item_size;
148
149 if (item != last) {
150 next = (u_char *) item + item_size;
150 next = nxt_pointer_to(item, item_size);
151
152 nxt_memmove(item, next, end - next);
153 }
154
155 vector->items--;
156}
151
152 nxt_memmove(item, next, end - next);
153 }
154
155 vector->items--;
156}