zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH 2/2] Start using the new arrlen_ge() / arrlen_le() helpers.
Date: Sat, 30 Jul 2016 13:11:51 +0000	[thread overview]
Message-ID: <1469884311-3264-2-git-send-email-danielsh@tarsus.local2> (raw)
In-Reply-To: <1469884311-3264-1-git-send-email-danielsh@tarsus.local2>

---
 Src/Modules/terminfo.c | 2 +-
 Src/Modules/zutil.c    | 4 ++--
 Src/builtin.c          | 6 +++---
 Src/params.c           | 4 ++--
 Src/prompt.c           | 6 +++---
 Src/utils.c            | 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
index e0439af..bbd3258 100644
--- a/Src/Modules/terminfo.c
+++ b/Src/Modules/terminfo.c
@@ -99,7 +99,7 @@ bin_echoti(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 	return 1;
     }
     /* check that the number of arguments provided is not too high */
-    if (arrlen(argv) > 9) {
+    if (arrlen_gt(argv, 9)) {
         zwarnnam(name, "too many arguments");
         return 1;
     }
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 477575c..d95c0c2 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -472,7 +472,7 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 	Patprog prog;
 	char *pat;
 
-	if (arrlen(args) < 2) {
+	if (arrlen_lt(args, 2)) {
 	    zwarnnam(nam, "not enough arguments");
 	    return 1;
 	}
@@ -491,7 +491,7 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 	Style s;
 	char *context, *stylename;
 
-	switch (arrlen(args)) {
+	switch (arrlen_ge(args, 3) ? 3 : arrlen(args)) {
 	case 2:
 	    context = args[0];
 	    stylename = args[1];
diff --git a/Src/builtin.c b/Src/builtin.c
index bfb9e69..fb14b2e 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3406,7 +3406,7 @@ bin_unset(char *name, char **argv, Options ops, int func)
 		    } else {
 			/* start is after the element for reverse index */
 			int start = vbuf.start - !!(vbuf.flags & VALFLAG_INV);
-			if (start < arrlen(vbuf.pm->u.arr)) {
+			if (arrlen_gt(vbuf.pm->u.arr, start)) {
 			    char *arr[2];
 			    arr[0] = "";
 			    arr[1] = 0;
@@ -5026,7 +5026,7 @@ bin_shift(char *name, char **argv, Options ops, UNUSED(int func))
     if (*argv) {
         for (; *argv; argv++)
             if ((s = getaparam(*argv))) {
-                if (num > arrlen(s)) {
+                if (arrlen_lt(s, num)) {
 		    zwarnnam(name, "shift count must be <= $#");
 		    ret++;
 		    continue;
@@ -5095,7 +5095,7 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
 	zoptind = 1;
 	optcind = 0;
     }
-    if(zoptind > arrlen(args))
+    if (arrlen_lt(args, zoptind))
 	/* no more options */
 	return 1;
 
diff --git a/Src/params.c b/Src/params.c
index 33f177e..0eda784 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2225,13 +2225,13 @@ getarrvalue(Value v)
 	v->start += arrlen(s);
     if (v->end < 0)
 	v->end += arrlen(s) + 1;
-    if (v->start > arrlen(s) || v->start < 0)
+    if (arrlen_lt(s, v->start) || v->start < 0)
 	s = arrdup(nular);
     else
 	s = arrdup(s + v->start);
     if (v->end <= v->start)
 	s[0] = NULL;
-    else if (v->end - v->start <= arrlen(s))
+    else if (arrlen_ge(s, v->end - v->start))
 	s[v->end - v->start] = NULL;
     return s;
 }
diff --git a/Src/prompt.c b/Src/prompt.c
index bb27453..d4f3898 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -395,11 +395,11 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 			test = 1;
 		    break;
 		case 'v':
-		    if (arrlen(psvar) >= arg)
+		    if (arrlen_ge(psvar, arg))
 			test = 1;
 		    break;
 		case 'V':
-		    if (arrlen(psvar) >= arg) {
+		    if (arrlen_ge(psvar, arg)) {
 			if (*psvar[(arg ? arg : 1) - 1])
 			    test = 1;
 		    }
@@ -736,7 +736,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		    arg = 1;
 		else if (arg < 0)
 		    arg += arrlen(psvar) + 1;
-		if (arg > 0 && arrlen(psvar) >= arg)
+		if (arg > 0 && arrlen_ge(psvar, arg))
 		    stradd(psvar[arg - 1]);
 		break;
 	    case 'E':
diff --git a/Src/utils.c b/Src/utils.c
index 95da960..0a5954f 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1157,7 +1157,7 @@ finddir(char *s)
     scanhashtable(nameddirtab, 0, 0, 0, finddir_scan, 0);
 
     ares = subst_string_by_hook("zsh_directory_name", "d", finddir_full);
-    if (ares && arrlen(ares) >= 2 &&
+    if (ares && arrlen_ge(ares, 2) &&
 	(len = (int)zstrtol(ares[1], NULL, 10)) > finddir_best) {
 	/* better duplicate this string since it's come from REPLY */
 	finddir_last = (Nameddir)hcalloc(sizeof(struct nameddir));


      reply	other threads:[~2016-07-30 13:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-30 13:11 [PATCH 1/2] Optimize indexing array parameters Daniel Shahaf
2016-07-30 13:11 ` Daniel Shahaf [this message]

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=1469884311-3264-2-git-send-email-danielsh@tarsus.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /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).