]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ngtcp2: adopt ngtcp2_conn_get_stream_user_data if available
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>
Sun, 19 Oct 2025 04:44:37 +0000 (13:44 +0900)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 19 Oct 2025 09:07:32 +0000 (11:07 +0200)
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

lib/vquic/curl_ngtcp2.c

index 421611520ad8a3aa8bd4a444bfa544d162c4bf3e..9478b8d0f38d6c9c061f91855259515d47f57dc6 100644 (file)
@@ -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,