Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: remove duplicate array values in parameter expansion



> Hrm.  That might not be a bad idea.  It'd be nice if we could figure out
> a way to optimize it when combined with (o) or (O).

Other than replacing qsort for the combined base, I wouldn't know what
to do.  Here it is; I used (n) since it was an unused letter in
'unique'.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.52
diff -u -r1.52 params.c
--- Src/params.c	2001/11/03 23:36:33	1.52
+++ Src/params.c	2001/12/16 20:42:50
@@ -2490,6 +2490,23 @@
 	    }
 }
 
+/**/
+void
+zhuniqarray(char **x)
+{
+    char **t, **p = x;
+
+    if (!x || !*x)
+	return;
+    while (*++p)
+	for (t = x; t < p; t++)
+	    if (!strcmp(*p, *t)) {
+		*p = NULL;
+		for (t = p--; (*t = t[1]) != NULL; t++);
+		break;
+	    }
+}
+
 /* Function to get value of special parameter `#' and `ARGC' */
 
 /**/
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.25
diff -u -r1.25 subst.c
--- Src/subst.c	2001/11/03 23:34:50	1.25
+++ Src/subst.c	2001/12/16 20:42:50
@@ -767,6 +767,7 @@
     int flags = 0;
     int flnum = 0;
     int sortit = 0, casind = 0;
+    int unique = 0;
     int casmod = 0;
     int quotemod = 0, quotetype = 0, quoteerr = 0;
     int visiblemod = 0;
@@ -996,6 +997,10 @@
 		    shsplit = 1;
 		    break;
 
+		case 'n':
+		    unique = 1;
+		    break;
+
 		default:
 		  flagerr:
 		    zerr("error in flags", NULL, 0);
@@ -1872,6 +1877,14 @@
 	    strcpy(*str, fstr);
 	    setdata(n, y);
 	    return n;
+	}
+	if (unique) {
+/*	    if(!copied) */
+		aval = arrdup(aval);
+
+	    i = arrlen(aval);
+	    if (i > 1)
+		zhuniqarray(aval);
 	}
 	if (sortit) {
 	    static CompareFn sortfn[] = {



Messages sorted by: Reverse Date, Date, Thread, Author