|
zpmod
b19981f
High-performance Zsh module for script optimization and filesystem helpers
|
Prototype stub for zpmod when building out-of-tree. More...
#include "zpmod_utils.h"#include "zpmod_source.h"#include "zpmod_fpath.h"#include "zpmod_source_hot.h"#include "zpmod_fs.h"Go to the source code of this file.
Macros | |
| #define | ZPMOD_PRO |
Functions | |
| int | bin_custom_dot (char *name, char **argv, Options ops, int func) |
| int | bin_readarray (char *nam, char **argv, Options ops, int func) |
| readarray builtin entrypoint More... | |
| void | zpmod_usage (void) |
Print usage for the zpmod builtin. More... | |
| int | setup_ (Module m) |
| int | features_ (Module m, char ***features) |
| Provide feature list (builtins) to zsh. More... | |
| int | enables_ (Module m, int **enables) |
| Enable/disable builtins as requested by the shell. More... | |
| int | boot_ (Module m) |
| int | cleanup_ (Module m) |
| Cleanup features when unloading. More... | |
| int | finish_ (Module m) |
| char * | zp_build_source_report (int no_paths, int *rep_size) |
| char * | zp_unmetafy_zalloc (const char *to_copy, int *new_len) |
| Duplicate and unmetafy a zsh string with zalloc; see header for details. More... | |
| char * | my_ztrdup_glen (const char *s, unsigned *len_ret) |
| zalloc-backed strdup with length out parameter. More... | |
| void | zp_freeparamnode (HashNode hn) |
| int | cmd_dirlist (char *nam, char **argv) |
| int | cmd_pathstat (char *nam, char **argv) |
| int | cmd_readfile (char *nam, char **argv) |
| int | zp_path_warmup_core (const char *nam, int quiet, int prune_missing, int dry_run) |
| Implements path-warmup functionality for executable discovery and path pruning. More... | |
| int | cmd_source_study (char *nam, char **argv) |
| int | cmd_fpath_index (char *nam, char **argv) |
Implements zpmod fpath-index with intelligent skip detection. More... | |
| int | cmd_source_hot (char *nam, char **argv) |
Implements zpmod source-hot. More... | |
Prototype stub for zpmod when building out-of-tree.
Definition in file zpmod.pro.
| int bin_custom_dot | ( | char * | name, |
| char ** | argv, | ||
| Options | ops, | ||
| int | func | ||
| ) |
| int bin_readarray | ( | char * | nam, |
| char ** | argv, | ||
| Options | ops, | ||
| int | func | ||
| ) |
readarray builtin entrypoint
Definition at line 26 of file readarray.c.
References setaparam(), setsparam(), unsetparam(), zalloc(), zfree(), zrealloc(), zsfree(), ztrdup(), and zwarnnam().
| int boot_ | ( | Module | m | ) |
| int cmd_dirlist | ( | char * | nam, |
| char ** | argv | ||
| ) |
Definition at line 348 of file zpmod_builtin.c.
References zp_dirlist_core(), and zwarnnam().
Referenced by bin_zpmod().
| int cmd_fpath_index | ( | char * | nam, |
| char ** | argv | ||
| ) |
Implements zpmod fpath-index with intelligent skip detection.
Generates function-to-path mappings from FPATH directories with performance optimization through skip detection that avoids rebuilding unchanged indexes.
The generated index uses a structured format for reliable skip detection:
The skip detection was redesigned to handle missing directories consistently, fixing a critical issue where mtime mismatches caused unnecessary rebuilds.
Original Problem: When a directory didn't exist during index generation, we recorded -1 as the mtime. However, if the directory appeared later or stat() behaved differently during verification, we'd get a mismatch and force an unnecessary rebuild.
Solution: Unified mtime handling ensures consistent comparison:
stat() failure → record -1stat() failure → use -1 for comparison| nam | Builtin name for error reporting |
| argv | Command arguments (–out, –rebuild, –preload) |
Definition at line 57 of file fpath.c.
References addhashnode(), dupstring(), getaparam(), gethashnode2(), shfunctab, zalloc(), ztrdup(), and zwarnnam().
Referenced by bin_zpmod().
| int cmd_pathstat | ( | char * | nam, |
| char ** | argv | ||
| ) |
Definition at line 381 of file zpmod_builtin.c.
References zp_icon(), zp_pathstat_core(), zp_take_opt_with_arg(), and zwarnnam().
Referenced by bin_zpmod().
| int cmd_readfile | ( | char * | nam, |
| char ** | argv | ||
| ) |
Definition at line 418 of file zpmod_builtin.c.
References zp_readfile_core(), and zwarnnam().
Referenced by bin_zpmod().
| int cmd_source_hot | ( | char * | nam, |
| char ** | argv | ||
| ) |
Implements zpmod source-hot.
| nam | The builtin name. |
| argv | Subcommand arguments. |
Definition at line 37 of file source_hot.c.
References arrlen(), compare_hot_scripts(), hot_script_t::count, getaparam(), hot_script_t::path, path, hot_script_t::total_ms, zalloc(), zfree(), zsfree(), ztrdup(), and zwarnnam().
Referenced by bin_zpmod().
| int cmd_source_study | ( | char * | nam, |
| char ** | argv | ||
| ) |
Definition at line 313 of file zpmod_builtin.c.
References zp_source_study_core(), and zwarnnam().
Referenced by bin_zpmod().
| int enables_ | ( | Module | m, |
| int ** | enables | ||
| ) |
| int features_ | ( | Module | m, |
| char *** | features | ||
| ) |
| int finish_ | ( | Module | m | ) |
| char* my_ztrdup_glen | ( | const char * | s, |
| unsigned * | len_ret | ||
| ) |
zalloc-backed strdup with length out parameter.
Duplicate a C string using zalloc and report length.
Definition at line 63 of file utils.c.
References zalloc().
Referenced by zp_unmetafy_zalloc().
| int setup_ | ( | Module | m | ) |
| char* zp_build_source_report | ( | int | no_paths, |
| int * | rep_size | ||
| ) |
Definition at line 670 of file source.c.
References source_event::duration, zp_sevent_node::event, source_event::file_name, source_event::full_path, gethashnode2(), zalloc(), zfree(), zp_icon(), zp_sevent_count, zp_source_events, zrealloc(), and ztrdup().
| void zp_freeparamnode | ( | HashNode | hn | ) |
| int zp_path_warmup_core | ( | const char * | nam, |
| int | quiet, | ||
| int | prune_missing, | ||
| int | dry_run | ||
| ) |
Implements path-warmup functionality for executable discovery and path pruning.
Scan $PATH directories to warm filesystem caches and prepare command lookup.
This function provides two main features:
The prune functionality was redesigned to avoid memory corruption issues that occurred when mixing getaparam("path") results with setaparam("path") calls. The original implementation caused double-free errors due to zsh's parameter management internals.
Solution: Use a two-pass approach with separate array construction:
ztrdup() for proper string ownershipsetaparam("path", new_array) without dependency on getaparam() result| nam | Builtin name for error reporting |
| quiet | Suppress progress messages if true |
| prune_missing | Remove non-existent directories from path if true |
| dry_run | Report what would be pruned without making changes if true |
Definition at line 254 of file fs.c.
References arrlen(), getaparam(), PATH_MAX, setaparam(), zalloc(), and ztrdup().
Referenced by bin_zpmod().
| char* zp_unmetafy_zalloc | ( | const char * | to_copy, |
| int * | new_len | ||
| ) |
Duplicate and unmetafy a zsh string with zalloc; see header for details.
Duplicate and unmetafy a zsh string using zsh allocators.
Definition at line 76 of file utils.c.
References my_ztrdup_glen(), unmetafy(), zalloc(), and zfree().
Referenced by cmd_report_append(), zp_dirlist_core(), zp_pathstat_core(), and zp_readfile_core().
| void zpmod_usage | ( | void | ) |
Print usage for the zpmod builtin.
Definition at line 96 of file zpmod_builtin.c.
References zp_icon().
Referenced by bin_zpmod().