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

PATCH: parameters again



I just thought of an easy way to speed up the often needed ${(k)...}
on the special hashes from the parameter modules. Should have thought
of that before...

This avoids calculating the values if they aren't needed.

Bye
 Sven

diff -u oldsrc/Modules/parameter.c Src/Modules/parameter.c
--- oldsrc/Modules/parameter.c	Thu Oct 28 10:13:10 1999
+++ Src/Modules/parameter.c	Thu Oct 28 10:23:34 1999
@@ -181,7 +181,8 @@
     for (i = 0; i < realparamtab->hsize; i++)
 	for (hn = realparamtab->nodes[i]; hn; hn = hn->next) {
 	    pm.nam = hn->nam;
-	    if (func != scancountparams)
+	    if (func != scancountparams &&
+		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
 		pm.u.str = paramtypestr((Param) hn);
 	    func((HashNode) &pm, flags);
 	}
@@ -312,7 +313,8 @@
 	for (hn = cmdnamtab->nodes[i]; hn; hn = hn->next) {
 	    pm.nam = hn->nam;
 	    cmd = (Cmdnam) hn;
-	    if (func != scancountparams) {
+	    if (func != scancountparams &&
+		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
 		if (cmd->flags & HASHED)
 		    pm.u.str = cmd->u.cmd;
 		else {
@@ -513,7 +515,8 @@
 	for (hn = shfunctab->nodes[i]; hn; hn = hn->next) {
 	    if (dis ? (hn->flags & DISABLED) : !(hn->flags & DISABLED)) {
 		pm.nam = hn->nam;
-		if (func != scancountparams) {
+		if (func != scancountparams &&
+		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
 		    if (((Shfunc) hn)->flags & PM_UNDEFINED) {
 			Shfunc shf = (Shfunc) hn;
 			pm.u.str =
@@ -621,7 +624,8 @@
 	for (hn = builtintab->nodes[i]; hn; hn = hn->next) {
 	    if (dis ? (hn->flags & DISABLED) : !(hn->flags & DISABLED)) {
 		pm.nam = hn->nam;
-		if (func != scancountparams) {
+		if (func != scancountparams &&
+		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
 		    char *t = ((((Builtin) hn)->handlerfunc ||
 				(hn->flags & BINF_PREFIX)) ?
 			       "defined" : "undefined");
@@ -1054,7 +1058,8 @@
     pm.level = 0;
 
     while (he) {
-	if (func != scancountparams) {
+	if (func != scancountparams &&
+	    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
 	    sprintf(buf, "%d", he->histnum);
 	    pm.nam = dupstring(buf);
 	    pm.u.str = dupstring(he->text);
@@ -1175,7 +1180,8 @@
     for (job = 1; job < MAXJOB; job++) {
 	if (jobtab[job].stat && jobtab[job].procs &&
 	    !(jobtab[job].stat & STAT_NOPRINT)) {
-	    if (func != scancountparams) {
+	    if (func != scancountparams &&
+		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
 		sprintf(buf, "%d", job);
 		pm.nam = dupstring(buf);
 		pm.u.str = pmjobtext(job);
@@ -1279,7 +1285,8 @@
     for (job = 1; job < MAXJOB; job++) {
 	if (jobtab[job].stat && jobtab[job].procs &&
 	    !(jobtab[job].stat & STAT_NOPRINT)) {
-	    if (func != scancountparams) {
+	    if (func != scancountparams &&
+		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
 		sprintf(buf, "%d", job);
 		pm.nam = dupstring(buf);
 		pm.u.str = pmjobstate(job);
@@ -1410,7 +1417,8 @@
 	for (hn = nameddirtab->nodes[i]; hn; hn = hn->next) {
 	    if (!((nd = (Nameddir) hn)->flags & ND_USERNAME)) {
 		pm.nam = hn->nam;
-		if (func != scancountparams)
+		if (func != scancountparams &&
+		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
 		    pm.u.str = dupstring(nd->dir);
 		func((HashNode) &pm, flags);
 	    }
@@ -1477,7 +1485,8 @@
 	for (hn = nameddirtab->nodes[i]; hn; hn = hn->next) {
 	    if ((nd = (Nameddir) hn)->flags & ND_USERNAME) {
 		pm.nam = hn->nam;
-		if (func != scancountparams)
+		if (func != scancountparams &&
+		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
 		    pm.u.str = dupstring(nd->dir);
 		func((HashNode) &pm, flags);
 	    }
@@ -1693,7 +1702,8 @@
 		 (!global && !((al = (Alias) hn)->flags & ALIAS_GLOBAL))) &&
 		(dis ? (al->flags & DISABLED) : !(al->flags & DISABLED))) {
 		pm.nam = hn->nam;
-		if (func != scancountparams)
+		if (func != scancountparams &&
+		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
 		    pm.u.str = dupstring(al->text);
 		func((HashNode) &pm, flags);
 	    }
diff -u oldsrc/Zle/zleparameter.c Src/Zle/zleparameter.c
--- oldsrc/Zle/zleparameter.c	Thu Oct 28 10:12:58 1999
+++ Src/Zle/zleparameter.c	Thu Oct 28 10:25:34 1999
@@ -145,7 +145,8 @@
     for (i = 0; i < thingytab->hsize; i++)
 	for (hn = thingytab->nodes[i]; hn; hn = hn->next) {
 	    pm.nam = hn->nam;
-	    if (func != scancountparams)
+	    if (func != scancountparams &&
+		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
 		pm.u.str = widgetstr(((Thingy) hn)->widget);
 	    func((HashNode) &pm, flags);
 	}

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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