java-topology/defects/proton/patch/proton-0001-find_iface_constructor-linear-strcmp-scan.patch

35 lines
1.4 KiB
Diff

# UNDF: UNDF-2026-000000893
# proton-0001: find_iface_constructor linear strcmp scan O(C) per lookup
#
# File: lsteamclient/steamclient_generated.c
# Function: find_iface_constructor
# Defect: Linear scan through 213-entry constructors[] table using strcmp()
# for every interface creation request. Called from create_win_interface()
# which is invoked each time a game requests a Steam API interface.
# Impact: MEDIUM — O(C) where C=213 interface versions. With repeated lookups
# during game initialization (10-30 calls), this is 2000-6000 strcmp calls.
# Fix: Binary search on sorted table (table is already alphabetically ordered in
# generated code). Reduces O(C) to O(log C) = O(8) per lookup.
#
--- a/lsteamclient/steamclient_generated.c
+++ b/lsteamclient/steamclient_generated.c
@@ -222,9 +222,18 @@ iface_constructor find_iface_constructor( const char *iface_version )
{
- int i;
- for (i = 0; i < ARRAYSIZE(constructors); ++i)
- if (!strcmp( iface_version, constructors[i].iface_version ))
- return constructors[i].ctor;
+ int lo = 0, hi = ARRAYSIZE(constructors) - 1;
+ while (lo <= hi)
+ {
+ int mid = (lo + hi) / 2;
+ int cmp = strcmp( iface_version, constructors[mid].iface_version );
+ if (cmp == 0)
+ return constructors[mid].ctor;
+ if (cmp < 0)
+ hi = mid - 1;
+ else
+ lo = mid + 1;
+ }
return NULL;
}