cmd/ww: FOLD 1 — str-lift cstreq/cstreqlit/cstrendswithlit via strings.* (capstone)
Bodies only; signatures unchanged so call sites are untouched. The *u8 paths flow through the existing pathstr() NUL-bounded str view: cstreq/cstreqlit -> strings.compare()==0, cstrendswithlit -> strings.hassuffix(). bytecmp (enumeratedir sort, magnitude-sensitive) and bytecpy (raw selfdirinto memcpy, storage model) stay byte-level. main.combined.ww regenerated.
This commit is contained in:
@@ -2876,23 +2876,12 @@ fn pathstr(p: *u8) str = {
|
||||
};
|
||||
|
||||
fn cstreq(a: *u8, b: *u8) bool = {
|
||||
let i: u64 = 0u64;
|
||||
for (a[i] == b[i]) {
|
||||
if (a[i] == 0u8) { return true; };
|
||||
i += 1u64;
|
||||
};
|
||||
return false;
|
||||
return strings.compare(pathstr(a), pathstr(b)) == 0;
|
||||
};
|
||||
|
||||
// cstreqlit — compare a NUL-terminated *u8 to a ww string literal.
|
||||
fn cstreqlit(a: *u8, lit: str) bool = {
|
||||
let n: i32 = lit.len;
|
||||
let i: i32 = 0;
|
||||
for (i < n) {
|
||||
if (a[i] != lit[i]) { return false; };
|
||||
i += 1;
|
||||
};
|
||||
return a[n] == 0u8;
|
||||
return strings.compare(pathstr(a), lit) == 0;
|
||||
};
|
||||
|
||||
// memcpy
|
||||
@@ -3782,17 +3771,7 @@ fn buildone(selfdir: *u8, src: *u8, entryisdir: i32, out: *u8, incs: *u8, lf: *l
|
||||
// <dir>/<name>.ww or <dir>/<name>/<name>.ww
|
||||
|
||||
fn cstrendswithlit(p: *u8, lit: str) bool = {
|
||||
let plen: u64 = cstrlen(p);
|
||||
let slen: u64 = lit.len: u64;
|
||||
if (plen < slen) { return false; };
|
||||
let off: u64 = plen - slen;
|
||||
let i: i32 = 0;
|
||||
for (i < lit.len) {
|
||||
let iu: u64 = i: u64;
|
||||
if (p[off + iu] != lit[i]) { return false; };
|
||||
i += 1;
|
||||
};
|
||||
return true;
|
||||
return strings.hassuffix(pathstr(p), lit);
|
||||
};
|
||||
|
||||
// basenameoff — return the offset of the last path segment within `p`
|
||||
|
||||
@@ -42,23 +42,12 @@ fn pathstr(p: *u8) str = {
|
||||
};
|
||||
|
||||
fn cstreq(a: *u8, b: *u8) bool = {
|
||||
let i: u64 = 0u64;
|
||||
for (a[i] == b[i]) {
|
||||
if (a[i] == 0u8) { return true; };
|
||||
i += 1u64;
|
||||
};
|
||||
return false;
|
||||
return strings.compare(pathstr(a), pathstr(b)) == 0;
|
||||
};
|
||||
|
||||
// cstreqlit — compare a NUL-terminated *u8 to a ww string literal.
|
||||
fn cstreqlit(a: *u8, lit: str) bool = {
|
||||
let n: i32 = lit.len;
|
||||
let i: i32 = 0;
|
||||
for (i < n) {
|
||||
if (a[i] != lit[i]) { return false; };
|
||||
i += 1;
|
||||
};
|
||||
return a[n] == 0u8;
|
||||
return strings.compare(pathstr(a), lit) == 0;
|
||||
};
|
||||
|
||||
// memcpy
|
||||
@@ -948,17 +937,7 @@ fn buildone(selfdir: *u8, src: *u8, entryisdir: i32, out: *u8, incs: *u8, lf: *l
|
||||
// <dir>/<name>.ww or <dir>/<name>/<name>.ww
|
||||
|
||||
fn cstrendswithlit(p: *u8, lit: str) bool = {
|
||||
let plen: u64 = cstrlen(p);
|
||||
let slen: u64 = lit.len: u64;
|
||||
if (plen < slen) { return false; };
|
||||
let off: u64 = plen - slen;
|
||||
let i: i32 = 0;
|
||||
for (i < lit.len) {
|
||||
let iu: u64 = i: u64;
|
||||
if (p[off + iu] != lit[i]) { return false; };
|
||||
i += 1;
|
||||
};
|
||||
return true;
|
||||
return strings.hassuffix(pathstr(p), lit);
|
||||
};
|
||||
|
||||
// basenameoff — return the offset of the last path segment within `p`
|
||||
|
||||
Reference in New Issue
Block a user