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

Re: Avoid strlen calls after sprintf



Bart Schaefer wrote:
> In several of these cases it would also be possible to change
> dupstring() to dupstring_wlen(), because now the length is known
> before dup-ing.

Good point. I can only spot the one place.

Oliver

diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 61325ddd2..f8fe46914 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -489,7 +489,7 @@ static char *
 build_pos_string(LinkList list)
 {
     LinkNode node;
-    int l;
+    int l, buflen;
     char buf[40], *s;
     long p;
 
@@ -502,8 +502,9 @@ build_pos_string(LinkList list)
 	    l += 1 + sprintf(buf, ":%ld", -p);
 	else
 #endif
-	l += 1 + sprintf(buf, "%ld", p);
-	setdata(node, dupstring(buf));
+	buflen = sprintf(buf, "%ld", p);
+	setdata(node, dupstring_wlen(buf, buflen));
+	l += 1 + buflen;
     }
     s = (char *) zalloc(l * sizeof(char));
     *s = 0;




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