[libc-commits] [libc] [libc][stdlib] Avoid scanning values during environment lookup (PR #228633)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Mon Oct 5 05:04:41 PDT 2026


================
@@ -82,10 +82,33 @@ cpp::optional<size_t> EnvironmentManager::find_var(cpp::string_view name) {
   if (!env_array)
     return cpp::nullopt;
 
-  for (size_t i = 0; i < count; i++) {
-    cpp::string_view current(env_array[i]);
-    if (current.starts_with(name) && current.size() > name.size() &&
-        current[name.size()] == '=')
+  // Compare entries directly: constructing a string_view from the entry's C
----------------
kaladron wrote:

The comments in this function are a bit too verbose for the amount of information given.  I think you could drop the first 3 lines and have just the 4th line and it would still convey the needed information.

(Similar feedback for the rest of the function)

https://github.com/llvm/llvm-project/pull/228633


More information about the libc-commits mailing list