From: Tatsuhiro Tsujikawa Date: Sun, 19 Oct 2025 04:44:37 +0000 (+0900) Subject: ngtcp2: adopt ngtcp2_conn_get_stream_user_data if available X-Git-Tag: rc-8_17_0-2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0798466a819245549a2041f4230a1dbd12a079d;p=thirdparty%2Fcurl.git ngtcp2: adopt ngtcp2_conn_get_stream_user_data if available Adopt ngtcp2_conn_get_stream_user_data which has been available since ngtcp2 v1.17.0. This improves the time complexity of searching h3_stream_ctx from O(n) to O(1) where n is the number of stream. Closes #19132 --- diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 421611520a..9478b8d0f3 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -300,6 +300,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, return CURLE_OK; } +#if NGTCP2_VERSION_NUM < 0x011100 struct cf_ngtcp2_sfind_ctx { curl_int64_t stream_id; struct h3_stream_ctx *stream; @@ -328,6 +329,20 @@ cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, curl_int64_t stream_id) Curl_uint_hash_visit(&ctx->streams, cf_ngtcp2_sfind, &fctx); return fctx.stream; } +#else +static struct h3_stream_ctx *cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, + curl_int64_t stream_id) +{ + struct Curl_easy *data = + ngtcp2_conn_get_stream_user_data(ctx->qconn, stream_id); + + if(!data) { + return NULL; + } + + return H3_STREAM_CTX(ctx, data); +} +#endif static void cf_ngtcp2_stream_close(struct Curl_cfilter *cf, struct Curl_easy *data,