| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: lst.c,v 1.90 2020/10/25 13:06:12 rillig Exp $ */ | | 1 | /* $NetBSD: lst.c,v 1.91 2020/10/28 02:43:16 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include "make.h" | | 35 | #include "make.h" |
36 | | | 36 | |
37 | MAKE_RCSID("$NetBSD: lst.c,v 1.90 2020/10/25 13:06:12 rillig Exp $"); | | 37 | MAKE_RCSID("$NetBSD: lst.c,v 1.91 2020/10/28 02:43:16 rillig Exp $"); |
38 | | | 38 | |
39 | static ListNode * | | 39 | static ListNode * |
40 | LstNodeNew(ListNode *prev, ListNode *next, void *datum) | | 40 | LstNodeNew(ListNode *prev, ListNode *next, void *datum) |
41 | { | | 41 | { |
42 | ListNode *node = bmake_malloc(sizeof *node); | | 42 | ListNode *node = bmake_malloc(sizeof *node); |
43 | node->prev = prev; | | 43 | node->prev = prev; |
44 | node->next = next; | | 44 | node->next = next; |
45 | node->datum = datum; | | 45 | node->datum = datum; |
46 | return node; | | 46 | return node; |
47 | } | | 47 | } |
48 | | | 48 | |
49 | /* Create and initialize a new, empty list. */ | | 49 | /* Create and initialize a new, empty list. */ |
50 | List * | | 50 | List * |
| @@ -273,35 +273,26 @@ Lst_Dequeue(List *list) | | | @@ -273,35 +273,26 @@ Lst_Dequeue(List *list) |
273 | assert(datum != NULL); /* since NULL would mean end of the list */ | | 273 | assert(datum != NULL); /* since NULL would mean end of the list */ |
274 | return datum; | | 274 | return datum; |
275 | } | | 275 | } |
276 | | | 276 | |
277 | void | | 277 | void |
278 | Vector_Init(Vector *v, size_t itemSize) | | 278 | Vector_Init(Vector *v, size_t itemSize) |
279 | { | | 279 | { |
280 | v->len = 0; | | 280 | v->len = 0; |
281 | v->priv_cap = 10; | | 281 | v->priv_cap = 10; |
282 | v->itemSize = itemSize; | | 282 | v->itemSize = itemSize; |
283 | v->items = bmake_malloc(v->priv_cap * v->itemSize); | | 283 | v->items = bmake_malloc(v->priv_cap * v->itemSize); |
284 | } | | 284 | } |
285 | | | 285 | |
286 | /* Return the pointer to the given item in the vector. | | | |
287 | * The returned data is valid until the next modifying operation. */ | | | |
288 | void * | | | |
289 | Vector_Get(Vector *v, size_t i) | | | |
290 | { | | | |
291 | unsigned char *items = v->items; | | | |
292 | return items + i * v->itemSize; | | | |
293 | } | | | |
294 | | | | |
295 | /* Add space for a new item to the vector and return a pointer to that space. | | 286 | /* Add space for a new item to the vector and return a pointer to that space. |
296 | * The returned data is valid until the next modifying operation. */ | | 287 | * The returned data is valid until the next modifying operation. */ |
297 | void * | | 288 | void * |
298 | Vector_Push(Vector *v) | | 289 | Vector_Push(Vector *v) |
299 | { | | 290 | { |
300 | if (v->len >= v->priv_cap) { | | 291 | if (v->len >= v->priv_cap) { |
301 | v->priv_cap *= 2; | | 292 | v->priv_cap *= 2; |
302 | v->items = bmake_realloc(v->items, v->priv_cap * v->itemSize); | | 293 | v->items = bmake_realloc(v->items, v->priv_cap * v->itemSize); |
303 | } | | 294 | } |
304 | v->len++; | | 295 | v->len++; |
305 | return Vector_Get(v, v->len - 1); | | 296 | return Vector_Get(v, v->len - 1); |
306 | } | | 297 | } |
307 | | | 298 | |