Skip to content

Commit

Permalink
Merge pull request #224 from ngtcp2/remove-nghttp3-min-max
Browse files Browse the repository at this point in the history
Remove nghttp3_min and nghttp3_max
  • Loading branch information
tatsuhiro-t authored May 12, 2024
2 parents 3918cdd + b1dc9a0 commit 0070208
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 32 deletions.
6 changes: 3 additions & 3 deletions lib/nghttp3_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
}

conn->rx.max_stream_id_bidi =
nghttp3_max(conn->rx.max_stream_id_bidi, stream_id);
nghttp3_max_int64(conn->rx.max_stream_id_bidi, stream_id);
rv = nghttp3_conn_create_stream(conn, &stream, stream_id);
if (rv != 0) {
return rv;
Expand Down Expand Up @@ -1705,7 +1705,7 @@ int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn,
dest->qpack_blocked_streams = (size_t)ent->value;

nghttp3_qpack_encoder_set_max_blocked_streams(
&conn->qenc, (size_t)nghttp3_min(100, ent->value));
&conn->qenc, (size_t)nghttp3_min_uint64(100, ent->value));
break;
case NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL:
if (!conn->server) {
Expand Down Expand Up @@ -1784,7 +1784,7 @@ conn_on_priority_update_stream(nghttp3_conn *conn,
}

conn->rx.max_stream_id_bidi =
nghttp3_max(conn->rx.max_stream_id_bidi, stream_id);
nghttp3_max_int64(conn->rx.max_stream_id_bidi, stream_id);
rv = nghttp3_conn_create_stream(conn, &stream, stream_id);
if (rv != 0) {
return rv;
Expand Down
4 changes: 2 additions & 2 deletions lib/nghttp3_ksl.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,6 @@ int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = lhs, *b = rhs;
return a->begin < b->begin &&
!(nghttp3_max(a->begin, b->begin) < nghttp3_min(a->end, b->end));
return a->begin < b->begin && !(nghttp3_max_uint64(a->begin, b->begin) <
nghttp3_min_uint64(a->end, b->end));
}
13 changes: 0 additions & 13 deletions lib/nghttp3_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@

#include <nghttp3/nghttp3.h>

#define nghttp3_min(A, B) ((A) < (B) ? (A) : (B))
#define nghttp3_max(A, B) ((A) > (B) ? (A) : (B))

#define nghttp3_struct_of(ptr, type, member) \
((type *)(void *)((char *)(ptr)-offsetof(type, member)))

Expand All @@ -48,11 +45,6 @@
variable-length integer encoding. */
#define NGHTTP3_MAX_VARINT ((1ULL << 62) - 1)

/*
* nghttp3_max variants but they are inline functions. The
* intermediate values are stored in parameters so that they are
* evaluated just once.
*/
#define nghttp3_max_def(SUFFIX, T) \
static inline T nghttp3_max_##SUFFIX(T a, T b) { return a < b ? b : a; }

Expand All @@ -66,11 +58,6 @@ nghttp3_max_def(uint32, uint32_t);
nghttp3_max_def(uint64, uint64_t);
nghttp3_max_def(size, size_t);

/*
* nghttp3_min variants but they are inline functions. The
* intermediate values are stored in parameters so that they are
* evaluated just once.
*/
#define nghttp3_min_def(SUFFIX, T) \
static inline T nghttp3_min_##SUFFIX(T a, T b) { return a < b ? a : b; }

Expand Down
12 changes: 6 additions & 6 deletions lib/nghttp3_qpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ void nghttp3_qpack_encoder_free(nghttp3_qpack_encoder *encoder) {

void nghttp3_qpack_encoder_set_max_dtable_capacity(
nghttp3_qpack_encoder *encoder, size_t max_dtable_capacity) {
max_dtable_capacity =
nghttp3_min(max_dtable_capacity, encoder->ctx.hard_max_dtable_capacity);
max_dtable_capacity = nghttp3_min_size(max_dtable_capacity,
encoder->ctx.hard_max_dtable_capacity);

if (encoder->ctx.max_dtable_capacity == max_dtable_capacity) {
return;
Expand Down Expand Up @@ -1377,7 +1377,7 @@ static int qpack_encoder_can_index(nghttp3_qpack_encoder *encoder, size_t need,

if (!nghttp3_pq_empty(&encoder->min_cnts)) {
gmin_cnt = nghttp3_qpack_encoder_get_min_cnt(encoder);
min_cnt = nghttp3_min(min_cnt, gmin_cnt);
min_cnt = nghttp3_min_uint64(min_cnt, gmin_cnt);
}

if (min_cnt == UINT64_MAX) {
Expand Down Expand Up @@ -2736,7 +2736,7 @@ static nghttp3_ssize qpack_read_string(nghttp3_qpack_read_state *rstate,
nghttp3_buf *dest, const uint8_t *begin,
const uint8_t *end) {
size_t len = (size_t)(end - begin);
size_t n = (size_t)nghttp3_min((uint64_t)len, rstate->left);
size_t n = (size_t)nghttp3_min_uint64((uint64_t)len, rstate->left);

dest->last = nghttp3_cpymem(dest->last, begin, n);

Expand Down Expand Up @@ -3247,7 +3247,7 @@ int nghttp3_qpack_decoder_dtable_literal_add(nghttp3_qpack_decoder *decoder) {
void nghttp3_qpack_decoder_set_max_concurrent_streams(
nghttp3_qpack_decoder *decoder, size_t max_concurrent_streams) {
decoder->max_concurrent_streams =
nghttp3_max(decoder->max_concurrent_streams, max_concurrent_streams);
nghttp3_max_size(decoder->max_concurrent_streams, max_concurrent_streams);
}

void nghttp3_qpack_stream_context_init(nghttp3_qpack_stream_context *sctx,
Expand Down Expand Up @@ -3706,7 +3706,7 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder,
}

static int qpack_decoder_dbuf_overflow(nghttp3_qpack_decoder *decoder) {
size_t limit = nghttp3_max(decoder->max_concurrent_streams, 100);
size_t limit = nghttp3_max_size(decoder->max_concurrent_streams, 100);
/* 10 = nghttp3_qpack_put_varint_len((1ULL << 62) - 1, 2)) */
return nghttp3_buf_len(&decoder->dbuf) > limit * 2 * 10;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/nghttp3_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end) {
nghttp3_range nghttp3_range_intersect(const nghttp3_range *a,
const nghttp3_range *b) {
nghttp3_range r = {0, 0};
uint64_t begin = nghttp3_max(a->begin, b->begin);
uint64_t end = nghttp3_min(a->end, b->end);
uint64_t begin = nghttp3_max_uint64(a->begin, b->begin);
uint64_t end = nghttp3_min_uint64(a->end, b->end);
if (begin < end) {
nghttp3_range_init(&r, begin, end);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/nghttp3_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
--rvint->left;
}

n = nghttp3_min(rvint->left, srclen);
n = nghttp3_min_size(rvint->left, srclen);

for (i = 0; i < n; ++i) {
rvint->acc = (rvint->acc << 8) + src[i];
Expand Down Expand Up @@ -996,7 +996,7 @@ int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *data,
if (len) {
buf = nghttp3_ringbuf_get(inq, len - 1);
bufleft = nghttp3_buf_left(buf);
nwrite = nghttp3_min(datalen, bufleft);
nwrite = nghttp3_min_size(datalen, bufleft);
buf->last = nghttp3_cpymem(buf->last, data, nwrite);
data += nwrite;
datalen -= nwrite;
Expand All @@ -1020,7 +1020,7 @@ int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *data,
buf = nghttp3_ringbuf_push_back(inq);
nghttp3_buf_wrap_init(buf, rawbuf, 16384);
bufleft = nghttp3_buf_left(buf);
nwrite = nghttp3_min(datalen, bufleft);
nwrite = nghttp3_min_size(datalen, bufleft);
buf->last = nghttp3_cpymem(buf->last, data, nwrite);
data += nwrite;
datalen -= nwrite;
Expand Down
4 changes: 2 additions & 2 deletions lib/nghttp3_tnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) {
tnode->cycle =
pq_get_first_cycle(pq) +
((nwrite == 0 || !tnode->pri.inc) ? 0 : nghttp3_max(1, penalty));
((nwrite == 0 || !tnode->pri.inc) ? 0 : nghttp3_max_uint64(1, penalty));
} else if (nwrite > 0) {
if (!tnode->pri.inc || nghttp3_pq_size(pq) == 1) {
return 0;
}

nghttp3_pq_remove(pq, &tnode->pe);
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
tnode->cycle += nghttp3_max(1, penalty);
tnode->cycle += nghttp3_max_uint64(1, penalty);
} else {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/nghttp3_conn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static nghttp3_ssize step_read_data(nghttp3_conn *conn, int64_t stream_id,
uint32_t *pflags, void *user_data,
void *stream_user_data) {
userdata *ud = user_data;
size_t n = nghttp3_min(ud->data.left, ud->data.step);
size_t n = nghttp3_min_size(ud->data.left, ud->data.step);

(void)conn;
(void)stream_id;
Expand Down

0 comments on commit 0070208

Please sign in to comment.