From a67259ca69abdd61b5b7e7f85cb08beaec126ddd Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Wed, 3 Jun 2026 04:19:38 +0900 Subject: [PATCH] wcc/cgen: localfind inline name-loop -> strings.compare (Wave-2 hand-rolled->lib) The open-coded len-guard + byte-by-byte equality loop in localfind is exactly strings.compare(ln, name) == 0 (==0 demands equal length AND equal bytes; no prefix false-match). Matches cstage cgen.c:1669 strcmp(l->name, name) == 0. The @-fallback streq + localfindnode streq calls are shared-helper calls, left for the wholesale swap (#17). Regenerated w6c + wwdump combined.ww (the only amalgamations embedding cgen.ww's localfind). --- selfhost/cmd/w6c/main.combined.ww | 11 ++--------- selfhost/cmd/wcc/cgen.ww | 11 ++--------- selfhost/cmd/wwdump/main.combined.ww | 11 ++--------- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index aa037f42..e7d492a2 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -31695,6 +31695,7 @@ import tok; import typ; import sym; import strconv; +import strings; import io; import memio; // Split files. Bundler pulls these in transitively so consumers only @@ -32337,15 +32338,7 @@ fn localfind(c: *cgen, name: str) i32 = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; - if (ln.len == name.len) { - let i: i32 = 0; - let eq: bool = true; - for (i < name.len) { - if (ln[i] != name[i]) { eq = false; i = name.len; } - else { i += 1; }; - }; - if (eq) { return l.off; }; - }; + if (strings.compare(ln, name) == 0) { return l.off; }; l = l.lnext; }; if (name.len > 0) { diff --git a/selfhost/cmd/wcc/cgen.ww b/selfhost/cmd/wcc/cgen.ww index d9614d9b..0e0725c2 100644 --- a/selfhost/cmd/wcc/cgen.ww +++ b/selfhost/cmd/wcc/cgen.ww @@ -30,6 +30,7 @@ import tok; import typ; import sym; import strconv; +import strings; import io; import memio; // Split files. Bundler pulls these in transitively so consumers only @@ -672,15 +673,7 @@ fn localfind(c: *cgen, name: str) i32 = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; - if (ln.len == name.len) { - let i: i32 = 0; - let eq: bool = true; - for (i < name.len) { - if (ln[i] != name[i]) { eq = false; i = name.len; } - else { i += 1; }; - }; - if (eq) { return l.off; }; - }; + if (strings.compare(ln, name) == 0) { return l.off; }; l = l.lnext; }; if (name.len > 0) { diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index d681b893..27c88ada 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -31695,6 +31695,7 @@ import tok; import typ; import sym; import strconv; +import strings; import io; import memio; // Split files. Bundler pulls these in transitively so consumers only @@ -32337,15 +32338,7 @@ fn localfind(c: *cgen, name: str) i32 = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; - if (ln.len == name.len) { - let i: i32 = 0; - let eq: bool = true; - for (i < name.len) { - if (ln[i] != name[i]) { eq = false; i = name.len; } - else { i += 1; }; - }; - if (eq) { return l.off; }; - }; + if (strings.compare(ln, name) == 0) { return l.off; }; l = l.lnext; }; if (name.len > 0) {