From 41a26204fbc1edec8fc4842d78bd6045e684cb1f Mon Sep 17 00:00:00 2001 From: tw93 Date: Wed, 4 Feb 2026 16:18:13 +0800 Subject: [PATCH] perf: skip redundant -name parameter when pattern is wildcard Optimization: - Skip -name "*" in safe_sudo_find_delete when pattern matches everything - Reduces unnecessary parameter passing to find command - Improves performance for operations that scan all files Rationale: - find -name "*" is redundant as it matches everything by default - Removing it reduces command overhead without changing behavior --- lib/core/file_ops.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/file_ops.sh b/lib/core/file_ops.sh index 3ad9f76..b2c3966 100644 --- a/lib/core/file_ops.sh +++ b/lib/core/file_ops.sh @@ -467,7 +467,12 @@ safe_sudo_find_delete() { debug_log "Finding, sudo, in $base_dir: $pattern, age: ${age_days}d, type: $type_filter" - local find_args=("-maxdepth" "5" "-name" "$pattern" "-type" "$type_filter") + local find_args=("-maxdepth" "5") + # Skip -name if pattern is "*" (matches everything anyway, but adds overhead) + if [[ "$pattern" != "*" ]]; then + find_args+=("-name" "$pattern") + fi + find_args+=("-type" "$type_filter") if [[ "$age_days" -gt 0 ]]; then find_args+=("-mtime" "+$age_days") fi