void queue_deinit_impl(struct queue *q)
{
- assert(q);
+ if (!kr_assume(q))
+ return;
struct queue_chunk *p = q->head;
while (p != NULL) {
struct queue_chunk *pf = p;
/* Return pointer to the space for the new element. */
void * queue_push_impl(struct queue *q)
{
- assert(q);
+ kr_require(q);
struct queue_chunk *t = q->tail; // shorthand
if (unlikely(!t)) {
- assert(!q->head && !q->len);
+ kr_require(!q->head && !q->len);
q->head = q->tail = t = queue_chunk_new(q);
} else
if (t->end == t->cap) {
t->begin = 0;
} else {
/* Let's grow the tail by another chunk. */
- assert(!t->next);
+ kr_require(!t->next);
t->next = queue_chunk_new(q);
t = q->tail = t->next;
}
}
- assert(t->end < t->cap);
+ kr_require(t->end < t->cap);
++(q->len);
++(t->end);
return t->data + q->item_size * (t->end - 1);
/* When we have choice, we optimize for further _push_head,
* i.e. when shifting or allocating a chunk,
* we store items on the tail-end of the chunk. */
- assert(q);
+ kr_require(q);
struct queue_chunk *h = q->head; // shorthand
if (unlikely(!h)) {
- assert(!q->tail && !q->len);
+ kr_require(!q->tail && !q->len);
h = q->head = q->tail = queue_chunk_new(q);
h->begin = h->end = h->cap;
} else
h->begin = h->end = h->cap;
}
}
- assert(h->begin > 0);
+ kr_require(h->begin > 0);
--(h->begin);
++(q->len);
return h->data + q->item_size * h->begin;