cg-string-efficiency

Refactors string comparisons and case conversions across polyglot codebases for zero-allocation efficiency.

Updated May 16, 2026
One-click install
npx skills add https://github.com/alimtvnetwork/img-pdf-v2 --skill cg-string-efficiency-alimtvnetwork
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cg-string-efficiency
Source: https://github.com/alimtvnetwork/img-pdf-v2/tree/main/.agents/skills/cg-string-efficiency
Command: npx skills add https://github.com/alimtvnetwork/img-pdf-v2 --skill cg-string-efficiency-alimtvnetwork

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate inefficient string operations like repeated case conversions, eager multi-field matching, and string concatenation in loops, causing unnecessary heap allocations and slower execution across Go, TypeScript, Python, PHP, Rust, and C# projects. ## Core Features & Use Cases - Zero-Allocation Case Folding: Replaces patterns like strings.ToLower(a) == strings.ToLower(b) with strings.EqualFold in Go, eq_ignore_ascii_case in Rust, and StringComparison.OrdinalIgnoreCase in C#. - Short-Circuiting & Loop Hoisting: Converts eager multi-field filter predicates into lazy early-return guards and hoists invariant case conversions outside loops. - Business Logic Preservation: Enforces a zero-regression mandate so substring containment semantics are never accidentally changed into equality comparisons. - Use Case: While auditing a Go service, the agent finds a filter loop lowering the search term on every iteration; it hoists the conversion, applies EqualFold for role checks, and commits everything in a single final commit. ## Quick Start Ask the agent to audit the repository for inefficient string comparisons and case conversions, then refactor them using zero-allocation equivalents while preserving existing behavior.

Frequently Asked Questions about cg-string-efficiency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace strings.ToLower comparisons in Go?

Replace strings.ToLower(a) == strings.ToLower(b) with strings.EqualFold(a, b), which performs Unicode case-folding with zero heap allocations and runs roughly ten times faster. This applies only to exact equality checks, not substring containment.

How to optimize case-insensitive string matching in loops?

Lower the search pattern once before the loop and pass the pre-lowered term into the matcher function. Inside matchers, use early guard returns so secondary fields are never lowered when the first condition already matches.

Does EqualFold work for substring containment checks?

No, EqualFold only tests exact equality and must never replace strings.Contains substring searches. For containment, keep Contains semantics but optimize by hoisting the lowered filter term and short-circuiting evaluation.

What is the C# equivalent of zero-allocation case-insensitive comparison?

Use string.Equals(a, b, StringComparison.OrdinalIgnoreCase) instead of a.ToLower() == b.ToLower(). This avoids allocating two new strings per comparison and matches the OrdinalIgnoreCase semantics required for identifiers.

When should string builders replace concatenation in loops?

Replace cumulative s += chunk concatenation inside loops with strings.Builder in Go, StringBuilder in C#, ''.join(parts) in Python, or array join in TypeScript. Repeated concatenation reallocates the full string on every iteration.