From: Geoff Wing <gcw@zsh.org>
To: Zsh Hackers <zsh-workers@sunsite.auc.dk>
Subject: PATCH: zsh-3.1.5-pws-24: complist colour listing optimisation
Date: Sun, 27 Jun 1999 17:51:32 +1000 [thread overview]
Message-ID: <19990627175131.A22749@primenet.com.au> (raw)
Heyla,
optimisations for output during colour lists. Duplicate sequences should
not achieve anything different from single sequences so don't output them.
Warning: unified diff follows :-)
--- Src/Zle/complist.c.orig Thu Jun 24 19:46:37 1999
+++ Src/Zle/complist.c Sun Jun 27 17:42:56 1999
@@ -230,48 +230,65 @@
if (!c->cols[COL_MI])
c->cols[COL_MI] = c->cols[COL_FI];
- if (!c->cols[COL_EC]) {
- char *e = (char *) zhalloc(strlen(c->cols[COL_LC]) +
- strlen(c->cols[COL_NO]) +
- strlen(c->cols[COL_RC]) + 1);
-
- /* If no `ec' was given, we is `<lc><no><rc>' as the default. */
- strcpy(e, c->cols[COL_LC]);
- strcat(e, c->cols[COL_NO]);
- strcat(e, c->cols[COL_RC]);
- c->cols[COL_EC] = e;
- }
return 0;
}
+static int last_col = COL_NO;
+
+static void
+zcputs(Listcols c, int colour)
+{
+ if (colour != last_col
+ && (last_col < COL_NO
+ || strcmp(c->cols[last_col], c->cols[colour]))) {
+ fputs(c->cols[COL_LC], shout);
+ fputs(c->cols[colour], shout);
+ fputs(c->cols[COL_RC], shout);
+ last_col = colour;
+ }
+ return;
+}
+
/* Get the terminal color string for the file with the given name and
* file modes. */
-static char *
-getcolstr(Listcols c, char *n, mode_t m)
+static void
+putcolstr(Listcols c, char *n, mode_t m)
{
+ int colour;
Extcol e;
for (e = c->exts; e; e = e->next)
- if (strsfx(e->ext, n))
- return e->col;
+ if (strsfx(e->ext, n)) { /* XXX: unoptimised if used */
+ if (last_col < COL_NO
+ || strcmp(c->cols[last_col], e->col)) {
+ fputs(c->cols[COL_LC], shout);
+ fputs(e->col, shout);
+ fputs(c->cols[COL_RC], shout);
+ }
+ last_col = COL_NO - 1;
+ return;
+ }
if (S_ISDIR(m))
- return c->cols[COL_DI];
+ colour = COL_DI;
else if (S_ISLNK(m))
- return c->cols[COL_LN];
+ colour = COL_LN;
else if (S_ISFIFO(m))
- return c->cols[COL_PI];
+ colour = COL_PI;
else if (S_ISSOCK(m))
- return c->cols[COL_SO];
+ colour = COL_SO;
else if (S_ISBLK(m))
- return c->cols[COL_BD];
+ colour = COL_BD;
else if (S_ISCHR(m))
- return c->cols[COL_CD];
+ colour = COL_CD;
else if (S_ISREG(m) && (m & S_IXUGO))
- return c->cols[COL_EX];
+ colour = COL_EX;
+ else
+ colour = COL_FI;
- return c->cols[COL_FI];
+ zcputs(c, colour);
+ return;
}
/* Information about the list shown. */
@@ -505,14 +522,15 @@
mc = 0;
q = p;
while (n && i--) {
- fputs(col.cols[COL_LC], shout);
if (!(m = *q)) {
- fputs(col.cols[COL_MI], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, COL_MI);
a = longest - 2;
while (a--)
putc(' ', shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
break;
}
hasm = 1;
@@ -539,20 +557,18 @@
zt = ztat(pb, &buf, 1);
if (cc >= 0)
- fputs(col.cols[cc], shout);
+ zcputs(&col, cc);
else if (zt)
- fputs(col.cols[COL_NO], shout);
+ zcputs(&col, COL_NO);
else
- fputs(getcolstr(&col, pb, buf.st_mode), shout);
- fputs(col.cols[COL_RC], shout);
+ putcolstr(&col, pb, buf.st_mode);
nicezputs(m->str, shout);
if (zt)
putc(' ', shout);
else
putc(file_type(buf.st_mode), shout);
} else {
- fputs(col.cols[cc >= 0 ? cc : COL_NO], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, cc >= 0 ? cc : COL_NO);
nicezputs(m->str, shout);
if (of)
putc(' ', shout);
@@ -560,13 +576,17 @@
a = longest - niceztrlen(m->str) - 2 - of;
while (a--)
putc(' ', shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
if (i) {
- fputs(col.cols[COL_LC], shout);
- fputs(col.cols[COL_NO], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, COL_NO);
fputs(" ", shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
}
if (--n)
for (j = nc; j && *q; j--)
@@ -574,13 +594,14 @@
mc++;
}
if (i > 0) {
- fputs(col.cols[COL_LC], shout);
- fputs(col.cols[COL_MI], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, COL_MI);
a = longest - 2;
while (a--)
putc(' ', shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
}
if (n) {
putc('\n', shout);
--
Geoff Wing : <gcw@pobox.com> Work URL: http://www.primenet.com.au/
Rxvt Stuff : <gcw@rxvt.org> Ego URL : http://pobox.com/~gcw/
Zsh Stuff : <gcw@zsh.org> Phone : (Australia) 0413 431 874
reply other threads:[~1999-06-27 8:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19990627175131.A22749@primenet.com.au \
--to=gcw@zsh.org \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).