summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-02-14 05:45:13 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-02-14 05:45:13 -0800
commitde0268077b27309540e2463242f12c5455e94b8e (patch)
tree7e6057c480d34becefd9f1c1c2bc3aa3319f6cec
parent8da8ba5a1cc7adf3ad5a4576510aae5c31ae0a6e (diff)
downloadtxr-de0268077b27309540e2463242f12c5455e94b8e.tar.gz
txr-de0268077b27309540e2463242f12c5455e94b8e.tar.bz2
txr-de0268077b27309540e2463242f12c5455e94b8e.zip
Few adjustments to no-implicit-conversion patch.
* lib.h (c_u): New inline function: unsafe conversion to ucnum, analogous to c_n for cnum. * hash.c (equal_hash, hash_iter_init): Use UINT_PTR_MAX instead of convert(ucnum, -1). (eql_hash): mp_hash returns unsigned long, so shouldn't require a cast to go to the uint_ptr_t. The types are of the same size, or at worst it is a widening. Also replace convert(ucnum, -1) by UINT_PTR_MAX here. Combining the TAG_CHR and TAG_NUM cases, and using c_u, which is more efficient since c_chr and c_num are non-inlined functions which redundantly check type. We no longer need a self variable in this function. (eq_hash): Same TAG_CHR and TAG_NUM changes as eql_hash. * regex.c (char_set_add): Reformat change to avoid line break across assignment.
-rw-r--r--hash.c20
-rw-r--r--lib.h6
-rw-r--r--regex.c4
3 files changed, 15 insertions, 15 deletions
diff --git a/hash.c b/hash.c
index 1b3030c2..1a481061 100644
--- a/hash.c
+++ b/hash.c
@@ -308,7 +308,7 @@ ucnum equal_hash(val obj, int *count, ucnum seed)
switch (type(obj)) {
case NIL:
- return convert(ucnum, -1);
+ return UINT_PTR_MAX;
case LIT:
return hash_c_str(litptr(obj), seed, count);
case CONS:
@@ -384,8 +384,6 @@ ucnum equal_hash(val obj, int *count, ucnum seed)
static ucnum eql_hash(val obj, int *count)
{
- val self = lit("hash-eql");
-
if ((*count)-- <= 0)
return 0;
@@ -393,9 +391,9 @@ static ucnum eql_hash(val obj, int *count)
case TAG_PTR:
switch (type(obj)) {
case NIL:
- return convert(ucnum, -1);
+ return UINT_PTR_MAX;
case BGNUM:
- return convert(ucnum, mp_hash(mp(obj)));
+ return mp_hash(mp(obj));
case FLNUM:
return hash_double(obj->fl.n);
case RNG:
@@ -409,9 +407,8 @@ static ucnum eql_hash(val obj, int *count)
}
}
case TAG_CHR:
- return convert(ucnum, c_chr(obj));
case TAG_NUM:
- return convert(ucnum, c_num(obj, self));
+ return c_u(obj);
case TAG_LIT:
switch (CHAR_BIT * sizeof (mem_t *)) {
case 32:
@@ -426,8 +423,6 @@ static ucnum eql_hash(val obj, int *count)
static ucnum eq_hash(val obj)
{
- val self = lit("hash");
-
switch (tag(obj)) {
case TAG_PTR:
switch (CHAR_BIT * sizeof (mem_t *)) {
@@ -437,9 +432,8 @@ static ucnum eq_hash(val obj)
return coerce(ucnum, obj) >> 5;
}
case TAG_CHR:
- return convert(ucnum, c_chr(obj));
case TAG_NUM:
- return convert(ucnum, c_num(obj, self));
+ return c_u(obj);
case TAG_LIT:
switch (CHAR_BIT * sizeof (mem_t *)) {
case 32:
@@ -1204,7 +1198,7 @@ void hash_iter_init(struct hash_iter *hi, val hash, val self)
{
struct hash *h = coerce(struct hash *, cobj_handle(self, hash, hash_cls));
hi->next = 0;
- hi->chain = convert(ucnum, -1);
+ hi->chain = UINT_PTR_MAX;
hi->cons = nil;
hi->hash = hash;
h->usecount++;
@@ -1214,7 +1208,7 @@ void us_hash_iter_init(struct hash_iter *hi, val hash)
{
struct hash *h = coerce(struct hash *, hash->co.handle);
hi->next = 0;
- hi->chain = convert(ucnum, -1);
+ hi->chain = UINT_PTR_MAX;
hi->cons = nil;
hi->hash = hash;
h->usecount++;
diff --git a/lib.h b/lib.h
index 972f97d2..5d095108 100644
--- a/lib.h
+++ b/lib.h
@@ -508,6 +508,12 @@ INLINE cnum c_n(val num)
{
return coerce(cnum, num) >> TAG_SHIFT;
}
+
+INLINE ucnum c_u(val num)
+{
+ return convert(ucnum, coerce(cnum, num) >> TAG_SHIFT);
+}
+
#if SIZEOF_WCHAR_T < 4
#define lit_noex(strlit) coerce(obj_t *,\
coerce(cnum, L"\0" L ## strlit L"\0" + 1) | \
diff --git a/regex.c b/regex.c
index 1d971625..213ac98f 100644
--- a/regex.c
+++ b/regex.c
@@ -597,8 +597,8 @@ static void char_set_add(char_set_t *set, wchar_t ch)
/* fallthrough */
case CHSET_SMALL:
assert (ch < 256);
- set->s.bitcell[CHAR_SET_INDEX(ch)] |=
- convert(bitcell_t, 1) << CHAR_SET_BIT(ch);
+ set->s.bitcell[CHAR_SET_INDEX(ch)] |= (convert(bitcell_t, 1)
+ << CHAR_SET_BIT(ch));
break;
case CHSET_LARGE:
assert (ch < 0x10000);