From 9164871fe4982bdd12866eb28ebded68ca3dacd1 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:17:20 +0000 Subject: refactor: dedupe StringHandler case-convert and substring-copy code emitLCase/emitUCase were a 45-line verbatim pair differing only in the libc callee; both now delegate to emitCaseConvert(Str, CaseFn). The malloc+memcpy+NUL tail duplicated across emitMid/emitRight/emitLeft moves into allocCopySubstring; each function keeps its own clamp logic, which is intentionally different. Co-Authored-By: Claude Fable 5 --- include/cps/StringHandler.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/cps') diff --git a/include/cps/StringHandler.h b/include/cps/StringHandler.h index 0af0cc7..e9a8752 100644 --- a/include/cps/StringHandler.h +++ b/include/cps/StringHandler.h @@ -19,6 +19,9 @@ class StringHandler { llvm::FunctionCallee ToUpperFunc; llvm::FunctionCallee ToLowerFunc; + llvm::Value *emitCaseConvert(llvm::Value *Str, llvm::FunctionCallee CaseFn); + llvm::Value *allocCopySubstring(llvm::Value *Src, llvm::Value *StartIdx, llvm::Value *Len); + public: StringHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M); -- cgit v1.3.1-4-g156e