Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-06-03 - Native string operations over regular expressions and walrus operator
**Learning:** For basic whitespace tokenization in Python, native `str.split()` (with no arguments) is heavily optimized in C, automatically handles consecutive whitespace, and performs significantly faster while avoiding regular expression compilation overhead compared to `re.split(r'\s+', value)`. Also, using the walrus operator (`:=`) in list comprehensions with redundant function calls (e.g. `[x.strip() for x in items if x.strip()]`) avoids executing the function multiple times and improves performance.
**Action:** Prefer `str.split()` for whitespace tokenization over `re.split` and use the walrus operator to compute and bind the result once in list comprehensions when filtering based on a computed value.
14 changes: 5 additions & 9 deletions helpers/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,14 @@ def discover_skill_md_files(root: Path) -> List[Path]:
def _coerce_list(value: Any) -> List[str]:
if value is None:
return []
if isinstance(value, list):
return [str(v).strip() for v in value if str(v).strip()]
if isinstance(value, tuple):
return [str(v).strip() for v in list(value) if str(v).strip()]
if isinstance(value, (list, tuple)):
return [sv for v in value if (sv := str(v).strip())]
if isinstance(value, str):
# Support comma-separated or space-delimited strings
if "," in value:
parts = [p.strip() for p in value.split(",")]
else:
parts = [p.strip() for p in re.split(r"\s+", value)]
return [p for p in parts if p]
return [str(value).strip()] if str(value).strip() else []
return [sv for p in value.split(",") if (sv := p.strip())]
return value.split()
return [sv] if (sv := str(value).strip()) else []


def _normalize_name(name: str) -> str:
Expand Down