1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 22:11:54 +02:00

53335: Remove unused dupstring_glen() function

Also make use of the dupstring_wlen() variant in more places to avoid a strlen()
This commit is contained in:
Oliver Kiddle 2025-01-30 12:41:53 +01:00
parent f7b5cc431b
commit 86a0891952
7 changed files with 24 additions and 44 deletions

View file

@ -1,5 +1,10 @@
2025-01-30 Oliver Kiddle <opk@zsh.org> 2025-01-30 Oliver Kiddle <opk@zsh.org>
* 53335: Src/hist.c, Src/string.c, Src/Zle/compcore.c,
Src/Zle/compctl.c, Src/Zle/compmatch.c, Src/Zle/computil.c:
Remove unused dupstring_glen() function and make use of the
dupstring_wlen() variant in more places to avoid a strlen()
* 53332, 53334: Src/builtin.c, Src/prompt.c, Src/Modules/stat.c, * 53332, 53334: Src/builtin.c, Src/prompt.c, Src/Modules/stat.c,
Src/Zle/compresult.c, Src/Zle/zle_misc.c: Src/Zle/compresult.c, Src/Zle/zle_misc.c:
Avoid strlen calls after sprintf Avoid strlen calls after sprintf

View file

@ -708,7 +708,7 @@ callcompfunc(char *s, char *fn)
sav = *ss; sav = *ss;
*ss = '\0'; *ss = '\0';
tmp = (linwhat == IN_MATH ? dupstring(s) : multiquote(s, 0)); tmp = (linwhat == IN_MATH ? dupstring_wlen(s, offs) : multiquote(s, 0));
untokenize(tmp); untokenize(tmp);
compprefix = ztrdup(tmp); compprefix = ztrdup(tmp);
*ss = sav; *ss = sav;
@ -1820,7 +1820,7 @@ set_comp_sep(void)
*/ */
sav = s[(i = swb - 1 - sqq + dq)]; sav = s[(i = swb - 1 - sqq + dq)];
s[i] = '\0'; s[i] = '\0';
qp = (qttype == QT_SINGLE) ? dupstring(s) : rembslash(s); qp = (qttype == QT_SINGLE) ? dupstring_wlen(s, i) : rembslash(s);
s[i] = sav; s[i] = sav;
if (swe < swb) if (swe < swb)
swe = swb; swe = swb;
@ -2244,10 +2244,10 @@ addmatches(Cadata dat, char **argv)
if (dat->aflags & CAF_MATCH) { if (dat->aflags & CAF_MATCH) {
lipre = dupstring(compiprefix); lipre = dupstring(compiprefix);
lisuf = dupstring(compisuffix); lisuf = dupstring(compisuffix);
lpre = dupstring(compprefix); llpl = strlen(compprefix);
lsuf = dupstring(compsuffix); llsl = strlen(compsuffix);
llpl = strlen(lpre); lpre = dupstring_wlen(compprefix, llpl);
llsl = strlen(lsuf); lsuf = dupstring_wlen(compsuffix, llsl);
/* This used to reference compqiprefix and compqisuffix, why? */ /* This used to reference compqiprefix and compqisuffix, why? */
if (llpl + (int)strlen(qipre) + (int)strlen(lipre) != origlpre if (llpl + (int)strlen(qipre) + (int)strlen(lipre) != origlpre
@ -2300,12 +2300,8 @@ addmatches(Cadata dat, char **argv)
for (p = lpre + 2; *p && *p != ')'; p++); for (p = lpre + 2; *p && *p != ')'; p++);
if (*p == ')') { if (*p == ')') {
char sav = p[1];
p[1] = '\0';
globflag = dupstring(lpre);
gfl = p - lpre + 1; gfl = p - lpre + 1;
p[1] = sav; globflag = dupstring_wlen(lpre, gfl);
lpre = p + 1; lpre = p + 1;
llpl -= gfl; llpl -= gfl;
@ -2731,7 +2727,7 @@ add_match_data(int alt, char *str, char *orig, Cline line,
sl = tsl; sl = tsl;
} }
if (qisl) { if (qisl) {
Cline qsl = bld_parts(dupstring(qisuf), qisl, qisl, NULL, NULL); Cline qsl = bld_parts(dupstring_wlen(qisuf, qisl), qisl, qisl, NULL, NULL);
qsl->flags |= CLF_SUF; qsl->flags |= CLF_SUF;
qsl->suffix = qsl->prefix; qsl->suffix = qsl->prefix;
@ -2814,7 +2810,7 @@ add_match_data(int alt, char *str, char *orig, Cline line,
line = p; line = p;
} }
if (qipl) { if (qipl) {
Cline lp, p = bld_parts(dupstring(qipre), qipl, qipl, &lp, NULL); Cline lp, p = bld_parts(dupstring_wlen(qipre, qipl), qipl, qipl, &lp, NULL);
lp->next = line; lp->next = line;
line = p; line = p;

View file

@ -3201,8 +3201,8 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
memcpy(lpre, s, lpl); memcpy(lpre, s, lpl);
lpre[lpl] = '\0'; lpre[lpl] = '\0';
qlpre = quotename(lpre); qlpre = quotename(lpre);
lsuf = dupstring(s + offs); lsl = strlen(s + offs);
lsl = strlen(lsuf); lsuf = dupstring_wlen(s + offs, lsl);
qlsuf = quotename(lsuf); qlsuf = quotename(lsuf);
/* First check for ~.../... */ /* First check for ~.../... */

View file

@ -1161,8 +1161,8 @@ comp_match(char *pfx, char *sfx, char *w, Patprog cp, Cline *clp, int qu,
/* We still break it into parts here, trying to build a sensible /* We still break it into parts here, trying to build a sensible
* cline list for these matches, too. */ * cline list for these matches, too. */
w = dupstring(w);
wl = strlen(w); wl = strlen(w);
w = dupstring_wlen(w, wl);
*clp = bld_parts(w, wl, wl, NULL, NULL); *clp = bld_parts(w, wl, wl, NULL, NULL);
*exact = 0; *exact = 0;
} else { } else {
@ -2127,7 +2127,7 @@ cmp_anchors(Cline o, Cline n, int join)
(j = join_strs(o->wlen, o->word, n->wlen, n->word))) { (j = join_strs(o->wlen, o->word, n->wlen, n->word))) {
o->flags |= CLF_JOIN; o->flags |= CLF_JOIN;
o->wlen = strlen(j); o->wlen = strlen(j);
o->word = dupstring(j); o->word = dupstring_wlen(j, o->wlen);
return 2; return 2;
} }

View file

@ -1296,8 +1296,7 @@ parse_cadef(char *nam, char **args)
int l = strlen(p) - 1; int l = strlen(p) - 1;
if (*p == '(' && p[l] == ')') { if (*p == '(' && p[l] == ')') {
axor = p = dupstring(p + 1); axor = p = dupstring_wlen(p + 1, l - 1);
p[l - 1] = '\0';
} else } else
axor = NULL; axor = NULL;
if (!*p) { if (!*p) {
@ -1317,8 +1316,7 @@ parse_cadef(char *nam, char **args)
p = *++args; p = *++args;
l = strlen(p) - 1; l = strlen(p) - 1;
if (*p == '(' && p[l] == ')') { if (*p == '(' && p[l] == ')') {
axor = p = dupstring(p + 1); axor = p = dupstring_wlen(p + 1, l - 1);
p[l - 1] = '\0';
} else } else
axor = NULL; axor = NULL;
if (!*p) { if (!*p) {
@ -1339,7 +1337,7 @@ parse_cadef(char *nam, char **args)
LinkList list = newlinklist(); LinkList list = newlinklist();
LinkNode node; LinkNode node;
char **xp, sav; char **xp;
while (*p && *p != ')') { while (*p && *p != ')') {
for (p++; inblank(*p); p++); for (p++; inblank(*p); p++);
@ -1351,11 +1349,8 @@ parse_cadef(char *nam, char **args)
if (!*p) if (!*p)
break; break;
sav = *p; addlinknode(list, dupstring_wlen(q, p - q));
*p = '\0';
addlinknode(list, dupstring(q));
xnum++; xnum++;
*p = sav;
} }
/* Oops, end-of-string. */ /* Oops, end-of-string. */
if (*p != ')') { if (*p != ')') {

View file

@ -3553,9 +3553,8 @@ bufferwords(LinkList list, char *buf, int *index, int flags)
} else if (buf) { } else if (buf) {
if (IS_REDIROP(tok) && tokfd >= 0) { if (IS_REDIROP(tok) && tokfd >= 0) {
char b[20]; char b[20];
int l = sprintf(b, "%d%s", tokfd, tokstrings[tok]);
sprintf(b, "%d%s", tokfd, tokstrings[tok]); addlinknode(list, dupstring_wlen(b, l));
addlinknode(list, dupstring(b));
num++; num++;
} else if (tok != NEWLIN) { } else if (tok != NEWLIN) {
addlinknode(list, dupstring(tokstrings[tok])); addlinknode(list, dupstring(tokstrings[tok]));

View file

@ -57,21 +57,6 @@ dupstring_wlen(const char *s, unsigned len)
return t; return t;
} }
/* Duplicate string on heap, returning length of string */
/**/
mod_export char *
dupstring_glen(const char *s, unsigned *len_ret)
{
char *t;
if (!s)
return NULL;
t = (char *) zhalloc((*len_ret = strlen((char *)s)) + 1);
strcpy(t, s);
return t;
}
/**/ /**/
mod_export char * mod_export char *
ztrdup(const char *s) ztrdup(const char *s)