From 3f87793404053b98fe0f6a20fafaf7e841f23f71 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 15 Jun 2019 00:27:50 -0700 Subject: Replace lt(x, zero) pattern. This slight inefficiency occurs in some 37 places in the code. In most places we replace lt(x, zero) with minusp(x). In a few places, !plusp(x) is used and surrounding logic is simplified. In one case, the silly pattern lt(x, zero) ? t : nil is replaced with just minusp(x). * buf.c (sub_buf, replace_buf): Replace lt. * combi.c (perm, rperm, comb, rcomb): Likewise. * eval.c (do_format_field): Likewise. * lib.c (listref, sub_list, replace_list, split_func, split_star_func, match_str, lazy_sub-str, sub_str, replace_str, sub_vec, replace_vec): Likewise. * match.c (weird_merge): Likewise. * regex.c (match_regex, match_regex_right_old, match_regex_right, regex_prefix_match, regex_range_left, regex_range_right): Likewise. --- buf.c | 8 ++++---- combi.c | 8 ++++---- eval.c | 4 ++-- lib.c | 38 +++++++++++++++++++------------------- match.c | 4 ++-- regex.c | 16 ++++++++-------- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/buf.c b/buf.c index 7d41d336..506ac45a 100644 --- a/buf.c +++ b/buf.c @@ -250,7 +250,7 @@ val sub_buf(val buf, val from, val to) from = zero; else if (from == t) from = len; - else if (lt(from, zero)) { + else if (minusp(from)) { from = plus(from, len); if (to == zero) to = len; @@ -258,7 +258,7 @@ val sub_buf(val buf, val from, val to) if (null_or_missing_p(to) || to == t) to = len; - else if (lt(to, zero)) + else if (minusp(to)) to = plus(to, len); from = max2(zero, min2(from, len)); @@ -300,7 +300,7 @@ val replace_buf(val buf, val items, val from, val to) } return buf; - } else if (lt(from, zero)) { + } else if (minusp(from)) { from = plus(from, len); if (to == zero) to = len; @@ -308,7 +308,7 @@ val replace_buf(val buf, val items, val from, val to) if (null_or_missing_p(to) || to == t) to = len; - else if (lt(to, zero)) + else if (minusp(to)) to = plus(to, len); from = max2(zero, min2(from, len)); diff --git a/combi.c b/combi.c index f2cd8159..e63cfffb 100644 --- a/combi.c +++ b/combi.c @@ -213,7 +213,7 @@ val perm(val seq, val k) if (!integerp(k)) type_mismatch(lit("perm: ~s is not an integer"), k, nao); - if (lt(k, zero)) + if (minusp(k)) uw_throwf(numeric_error_s, lit("perm: ~s is not a positive integer"), k, nao); } @@ -304,7 +304,7 @@ val rperm(val seq, val k) if (!integerp(k)) type_mismatch(lit("rperm: ~s is not an integer"), k, nao); - if (lt(k, zero)) + if (minusp(k)) uw_throwf(numeric_error_s, lit("rperm: ~s is not a positive integer"), k, nao); @@ -463,7 +463,7 @@ val comb(val seq, val k) if (!integerp(k)) type_mismatch(lit("comb: ~s is not an integer"), k, nao); - if (lt(k, zero)) + if (minusp(k)) uw_throwf(numeric_error_s, lit("comb: ~s is not a positive integer"), k, nao); @@ -593,7 +593,7 @@ val rcomb(val seq, val k) if (!integerp(k)) type_mismatch(lit("rcomb: ~s is not an integer"), k, nao); - if (lt(k, zero)) + if (minusp(k)) uw_throwf(numeric_error_s, lit("rcomb: ~s is not a positive integer"), k, nao); diff --git a/eval.c b/eval.c index f039ed2e..1ef2ef47 100644 --- a/eval.c +++ b/eval.c @@ -2722,8 +2722,8 @@ static val do_format_field(val obj, val n, val sep, } { - val right = lt(n, zero); - val width = if3(lt(n, zero), neg(n), n); + val right = minusp(n); + val width = if3(minusp(n), neg(n), n); val diff = minus(width, length_str(str)); if (le(diff, zero)) diff --git a/lib.c b/lib.c index de78d8a9..f1740e52 100644 --- a/lib.c +++ b/lib.c @@ -791,9 +791,9 @@ val lazy_conses(val list) val listref(val list, val ind) { gc_hint(list); - if (lt(ind, zero)) { + if (minusp(ind)) { ind = plus(ind, length_list(list)); - if (lt(ind, zero)) + if (minusp(ind)) return nil; } for (; gt(ind, zero); ind = minus(ind, one)) @@ -1375,7 +1375,7 @@ val sub_list(val list, val from, val to) from = zero; else if (from == t) from = nil; - else if (lt(from, zero)) { + else if (minusp(from)) { from = plus(from, len = length(list)); if (to == zero) to = nil; @@ -1383,7 +1383,7 @@ val sub_list(val list, val from, val to) if (to == t || null_or_missing_p(to)) to = nil; - else if (!null_or_missing_p(to) && lt(to, zero)) + else if (!null_or_missing_p(to) && minusp(to)) to = plus(to, if3(len, len, len = length(list))); gc_hint(list); @@ -1455,7 +1455,7 @@ val replace_list(val list, val items, val from, val to) } return list; - } else if (lt(from, zero)) { + } else if (minusp(from)) { from = plus(from, len ? len : (len = length(list))); if (to == zero) to = len; @@ -1463,7 +1463,7 @@ val replace_list(val list, val items, val from, val to) if (to == t || null_or_missing_p(to)) to = nil; - if (to && lt(to, zero)) + if (to && minusp(to)) to = plus(to, len ? len : (len = length(list))); gc_hint(list); @@ -2401,7 +2401,7 @@ static val split_func(val base, val lcons) raw_index); val index_rebased = minus(index, base); - if (lt(index_rebased, zero)) { + if (minusp(index_rebased)) { continue; } else { val first = sub(seq, zero, index_rebased); @@ -2441,7 +2441,7 @@ static val split_star_func(val base, val lcons) raw_index); val index_rebased = minus(index, base); - if (lt(index_rebased, zero)) { + if (minusp(index_rebased)) { continue; } else { val first = sub(seq, zero, index_rebased); @@ -3628,7 +3628,7 @@ val match_str(val bigstr, val str, val pos) return nil; } - return lt(i, zero) ? t : nil; + return minusp(i); } } @@ -3664,7 +3664,7 @@ static val lazy_sub_str(val lstr, val from, val to) } else if (from == t) { return null_string; } else { - if (lt(from, zero)) { + if (minusp(from)) { from = plus(from, len = length_str(lstr)); from = max2(zero, from); @@ -3681,7 +3681,7 @@ static val lazy_sub_str(val lstr, val from, val to) if (null_or_missing_p(to) || to == t) { to = t; } else { - if (lt(to, zero)) { + if (minusp(to)) { to = plus(to, len = length_str(lstr)); to = max(zero, to); } @@ -3722,7 +3722,7 @@ val sub_str(val str_in, val from, val to) from = zero; else if (from == t) return null_string; - else if (lt(from, zero)) { + else if (minusp(from)) { from = plus(from, len); if (to == zero) to = len; @@ -3730,7 +3730,7 @@ val sub_str(val str_in, val from, val to) if (null_or_missing_p(to) || to == t) to = len; - else if (lt(to, zero)) + else if (minusp(to)) to = plus(to, len); from = max2(zero, min2(from, len)); @@ -3783,7 +3783,7 @@ val replace_str(val str_in, val items, val from, val to) } return str_in; - } else if (lt(from, zero)) { + } else if (minusp(from)) { from = plus(from, len); if (to == zero) to = len; @@ -3791,7 +3791,7 @@ val replace_str(val str_in, val items, val from, val to) if (null_or_missing_p(to) || to == t) to = len; - else if (lt(to, zero)) + else if (minusp(to)) to = plus(to, len); from = max2(zero, min2(from, len)); @@ -7150,7 +7150,7 @@ val sub_vec(val vec_in, val from, val to) from = zero; else if (from == t) from = len; - else if (lt(from, zero)) { + else if (minusp(from)) { from = plus(from, len); if (to == zero) to = len; @@ -7158,7 +7158,7 @@ val sub_vec(val vec_in, val from, val to) if (null_or_missing_p(to) || to == t) to = len; - else if (lt(to, zero)) + else if (minusp(to)) to = plus(to, len); from = max2(zero, min2(from, len)); @@ -7212,7 +7212,7 @@ val replace_vec(val vec_in, val items, val from, val to) } return vec_in; - } else if (lt(from, zero)) { + } else if (minusp(from)) { from = plus(from, len); if (to == zero) to = len; @@ -7220,7 +7220,7 @@ val replace_vec(val vec_in, val items, val from, val to) if (null_or_missing_p(to) || to == t) to = len; - else if (lt(to, zero)) + else if (minusp(to)) to = plus(to, len); from = max2(zero, min2(from, len)); diff --git a/match.c b/match.c index 230b7be3..200a1fea 100644 --- a/match.c +++ b/match.c @@ -221,12 +221,12 @@ static val weird_merge(val left, val right) val left_depth = depth(left); val right_depth = depth(right); - while (lt(left_depth, right_depth) || zerop(left_depth)) { + while (!plusp(left_depth)) { left = cons(left, nil); left_depth = plus(left_depth, one); } - while (lt(right_depth, left_depth) || zerop(right_depth)) { + while (!plusp(right_depth)) { right = cons(right, nil); right_depth = plus(right_depth, one); } diff --git a/regex.c b/regex.c index 47f1e0c3..50a246c7 100644 --- a/regex.c +++ b/regex.c @@ -2701,9 +2701,9 @@ val match_regex(val str, val reg, val pos) if (null_or_missing_p(pos)) { pos = zero; - } else if (lt(pos, zero)) { + } else if (minusp(pos)) { pos = plus(pos, length_str(str)); - if (lt(pos, zero)) + if (minusp(pos)) return nil; } else if (length_str_lt(str, pos)) { return nil; @@ -2750,7 +2750,7 @@ static val match_regex_right_old(val str, val regex, val end) if (null_or_missing_p(end) || gt(end, slen)) end = slen; - else if (lt(end, zero)) + else if (minusp(end)) end = plus(end, slen); while (le(pos, end)) { @@ -2778,7 +2778,7 @@ val match_regex_right(val str, val regex, val end) end = len; } else if (minusp(end)) { end = plus(end, len); - if (lt(end, zero)) + if (minusp(end)) return nil; } else if (gt(end, len)) { return nil; @@ -2824,9 +2824,9 @@ val regex_prefix_match(val reg, val str, val pos) if (null_or_missing_p(pos)) { pos = zero; - } else if (lt(pos, zero)) { + } else if (minusp(pos)) { pos = plus(pos, length_str(str)); - if (lt(pos, zero)) + if (minusp(pos)) return nil; } else if (length_str_lt(str, pos)) { return nil; @@ -3045,7 +3045,7 @@ val regex_range_left(val regex, val arg1, val arg2) val len = match_regex(arg1, regex, arg2); return if2(len, rcons(zero, len)); } else { - val pos = if3(lt(arg1, zero), plus(arg1, length_str(arg2)), arg1); + val pos = if3(minusp(arg1), plus(arg1, length_str(arg2)), arg1); val new_pos = if3(minusp(pos), nil, match_regex(arg2, regex, pos)); return if2(new_pos, rcons(pos, new_pos)); } @@ -3062,7 +3062,7 @@ val regex_range_right(val regex, val arg1, val arg2) return nil; } } else { - val end = if3(lt(arg1, zero), plus(arg1, length_str(arg2)), arg1); + val end = if3(minusp(arg1), plus(arg1, length_str(arg2)), arg1); val len = match_regex_right(arg2, regex, end); return if2(len, rcons(minus(end, len), end)); } -- cgit v1.2.3