about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWayne Davison <wayned@users.sourceforge.net>2006-02-19 22:57:56 +0000
committerWayne Davison <wayned@users.sourceforge.net>2006-02-19 22:57:56 +0000
commit6c31a7dc68d680e55f14942f9bf746cd879b5833 (patch)
tree38dad0aeafce0437ac70741fe9b419e2cea4a40d
parente66dce41bccc73867efde01958d8d51f11041706 (diff)
downloadzsh-6c31a7dc68d680e55f14942f9bf746cd879b5833.tar.gz
zsh-6c31a7dc68d680e55f14942f9bf746cd879b5833.tar.xz
zsh-6c31a7dc68d680e55f14942f9bf746cd879b5833.zip
Made the realocation of the line buffer in add_match_data() use a
little more optimal size.  Also tweaked the code just a little.
-rw-r--r--Src/Zle/compcore.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index c0a5401bc..1f81f989f 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -2471,16 +2471,16 @@ add_match_data(int alt, char *str, char *orig, Cline line,
 	    memset(&mbs, '\0', sizeof mbs);
 	    if (!new_str) {
 		/* Be very pessimistic about how much space we'll need. */
-		new_str = zhalloc(stl*7 + 1);
+		new_str = zhalloc((t - str) + (fe - fs)*7 + 1);
 		memcpy(new_str, str, t - str);
 		t = new_str + (t - str);
 	    }
-	    /* Backup and output just the first bad char unless we
-	     * got an MB_INCOMPLETE at the end of the string. */
-	    f = fs;
+	    /* Output one byte from the start of this invalid multibyte
+	     * sequence unless we got MB_INCOMPLETE at the end of the
+	     * string, in which case we output all the incomplete bytes. */
 	    do {
-		if ((curchar = *f++) == Meta)
-		    curchar = *f++ ^ 32;
+		if ((curchar = *fs++) == Meta)
+		    curchar = *fs++ ^ 32;
 		*t++ = '$';
 		*t++ = '\'';
 		*t++ = '\\';
@@ -2488,8 +2488,9 @@ add_match_data(int alt, char *str, char *orig, Cline line,
 		*t++ = '0' + ((STOUC(curchar) >> 3) & 7);
 		*t++ = '0' + (STOUC(curchar) & 7);
 		*t++ = '\'';
-	    } while (cnt == MB_INCOMPLETE && f < fe);
-	    fs = f;
+	    } while (cnt == MB_INCOMPLETE && fs < fe);
+	    /* Scanning restarts from the spot after the char we skipped. */
+	    f = fs;
 	    break;
 	default:
 	    while (fs < f)