Skip to content

perf(all_variables_matching_prefix): avoid making list of all visible variables - #2

Open
akinomyoga wants to merge 4 commits into
develfrom
patch-all_variables_matching_prefix
Open

perf(all_variables_matching_prefix): avoid making list of all visible variables#2
akinomyoga wants to merge 4 commits into
develfrom
patch-all_variables_matching_prefix

Conversation

@akinomyoga

@akinomyogaakinomyoga commented Aug 13, 2026

Copy link
Copy Markdown
Member

A global variable is used to pass the current context in this patch, but another option is to extend vapply to accept an additional void* argument for a context that is passed to the function argument. However, this requires extension of map_over, flatten, and sh_var_map_func_t, which is a part of the exposed interface. Then, one might need to prepare a full set of versions accepting a context argument, such as vapply_ctx, map_over_ctx, flattern_ctx, sh_var_map_func_ctx_t, which seems too much for the present change.

Another possible improvement is to even reduce the construction of vlist because we finally want to get a list of variable names. We can pass (VAR_LIST*)0 to flatten to avoid constructing a new variable list and instead append the variable name to the strvec in the map function. However, to do that, we need to manually loop over shell_variables. In addition, the proper strvec_sort isn't prepared, so we need to extend strvec_sort. This possibility is implemented in d217f57.

@akinomyogaakinomyoga changed the title perf(all_variables_mathing_prefix): avoid making list of all visible variablesperf(all_variables_matching_prefix): avoid making list of all visible variablesAug 14, 2026
@akinomyoga
akinomyogaforce-pushed the patch-all_variables_matching_prefix branch 3 times, most recently from 731cb35 to 2097031CompareAugust 15, 2026 06:58
The original code probably does not cause any problems because the
caller will correctly fill elements and put the NULL terminator.
However, when we zero-initialize the contents, we should also
initialize the NULL terminator.
The hint text can be used to reduce the size of the generated list.
Filtering by the hint text is not mandatory. If the list is not too
large, the list_getter function can safely ignore the hint_text
argument. When list_getter fully performs the filtering by the hint
text, list_getter can set flag LIST_PREFIXFILTERED so that the
subsequent filtering at the caller can be skipped.
@akinomyoga
akinomyogaforce-pushed the patch-all_variables_matching_prefix branch 2 times, most recently from 4cc998b to 9c3169bCompareAugust 15, 2026 10:35
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@akinomyoga