ruri
ruri copied to clipboard
Optimize string processing by caching strlen() results in loops
37 loops across the codebase were calling strlen() in their condition on every iteration, resulting in O(n²) complexity for string traversal.
Changes
- cprintf.c (6 instances): Color parsing and formatted output
- k2v.c (29 instances): Key-value parsing, validation, and string manipulation
- mount.c (1 instance): Directory path creation
- ruri.c (1 instance): Argument parsing
Example
// Before: strlen() called n times = O(n²)
for (size_t i = 0; i < strlen(buf); i++) {
process(buf[i]);
}
// After: strlen() called once = O(n)
size_t len = strlen(buf);
for (size_t i = 0; i < len; i++) {
process(buf[i]);
}
For a 1000-character string, this reduces ~500K character comparisons to ~1K.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
Original prompt
Identify and suggest improvements to slow or inefficient code
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.