diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-02-14 06:58:14 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-02-14 06:58:14 -0800 |
commit | 8c25a6210a1fc44901fd6ebf7fb3f63c0ca5eec0 (patch) | |
tree | acb64699c567dba023fe5c3591fe96e22f3ef2ba | |
parent | 4477112731119ebc28d5e4a9dce858d8d008af36 (diff) | |
download | txr-8c25a6210a1fc44901fd6ebf7fb3f63c0ca5eec0.tar.gz txr-8c25a6210a1fc44901fd6ebf7fb3f63c0ca5eec0.tar.bz2 txr-8c25a6210a1fc44901fd6ebf7fb3f63c0ca5eec0.zip |
gethash_f: removing function.
Uses of gethash_f can be replaced with gethash_e, which
returns the hash cell directly rather than through a loc
argument. Code that needs the value can call cdr itself.
* hash.c (inhash, hash_isec, hash_update_1): Replace gethash_f
with gethash_e.
(gethash_f): Function removed.
* hash.h (gethash_f): Declaration removed.
* lib.c (use_sym, unuse_sym, find_symbol, unintern,
intern_fallback, in, sel, populate_obj_hash): Replace
gethash_f with gethash_e.
-rw-r--r-- | hash.c | 23 | ||||
-rw-r--r-- | hash.h | 1 | ||||
-rw-r--r-- | lib.c | 54 |
3 files changed, 33 insertions, 45 deletions
@@ -808,24 +808,16 @@ val gethash(val hash, val key) val inhash(val hash, val key, val init) { val self = lit("inhash"); - val cell; if (missingp(init)) { - gethash_f(self, hash, key, mkcloc(cell)); + return gethash_e(self, hash, key); } else { val new_p; - cell = gethash_c(self, hash, key, mkcloc(new_p)); + val cell = gethash_c(self, hash, key, mkcloc(new_p)); if (new_p) rplacd(cell, init); + return cell; } - - return cell; -} - -val gethash_f(val self, val hash, val key, loc found) -{ - set(found, gethash_e(self, hash, key)); - return cdr(deref(found)); } val gethash_n(val hash, val key, val notfound_val) @@ -1484,13 +1476,12 @@ val hash_isec(val hash1, val hash2, val join_func) entry; entry = hash_next(hiter)) { - val found; - val data2 = gethash_f(self, hash2, car(entry), mkcloc(found)); + val found = gethash_e(self, hash2, car(entry)); if (found) { if (missingp(join_func)) sethash(hout, car(entry), cdr(entry)); else - sethash(hout, car(entry), funcall2(join_func, cdr(entry), data2)); + sethash(hout, car(entry), funcall2(join_func, cdr(entry), cdr(found))); } } @@ -1535,8 +1526,8 @@ val hash_update_1(val hash, val key, val fun, val init) val self = lit("hash-update-1"); if (missingp(init)) { - val cons; - val data = gethash_f(self, hash, key, mkcloc(cons)); + val cons = gethash_e(self, hash, key); + val data = cdr(cons); if (cons) rplacd(cons, funcall1(fun, data)); return data; @@ -37,7 +37,6 @@ val gethash_e(val self, val hash, val key); val gethash(val hash, val key); val inhash(val hash, val key, val init); val gethash_n(val hash, val key, val notfound_val); -val gethash_f(val self, val hash, val key, loc found); val sethash(val hash, val key, val value); val pushhash(val hash, val key, val value); val remhash(val hash, val key); @@ -5397,8 +5397,8 @@ val use_sym(val symbol, val package_in) if (symbol_package(symbol) != package) { val name = symbol_name(symbol); - val found; - val existing = gethash_f(self, package->pk.symhash, name, mkcloc(found)); + val found = gethash_e(self, package->pk.symhash, name); + val existing = cdr(found); if (found && symbol_package(existing) == package) { if (existing == nil) @@ -5419,9 +5419,10 @@ val unuse_sym(val symbol, val package_in) val self = lit("unuse-sym"); val package = get_package(self, package_in, t); val name = symbol_name(symbol); - val found_visible, found_hidden; - val visible = gethash_f(self, package->pk.symhash, name, mkcloc(found_visible)); - val hidden = gethash_f(self, package->pk.hidhash, name, mkcloc(found_hidden)); + val found_visible = gethash_e(self, package->pk.symhash, name); + val found_hidden = gethash_e(self, package->pk.hidhash, name); + val visible = cdr(found_visible); + val hidden = cdr(found_hidden); if (!found_visible || visible != symbol) return nil; @@ -5584,13 +5585,13 @@ val find_symbol(val str, val package_in) { val self = lit("find-symbol"); val package = get_package(self, package_in, nil); - val found, sym; + val found; if (!stringp(str)) uw_throwf(error_s, lit("~a: name ~s isn't a string"), self, str, nao); - if ((sym = gethash_f(self, package->pk.symhash, str, mkcloc(found))) || found) - return sym; + if ((found = gethash_e(self, package->pk.symhash, str))) + return cdr(found); return zero; } @@ -5621,9 +5622,11 @@ val unintern(val symbol, val package_in) val self = lit("unintern"); val package = get_package(self, package_in, t); val name = symbol_name(symbol); - val found_visible, found_hidden; - val visible = gethash_f(self, package->pk.symhash, name, mkcloc(found_visible)); - val hidden = gethash_f(self, package->pk.hidhash, name, mkcloc(found_hidden)); + val found_visible = gethash_e(self, package->pk.symhash, name); + val found_hidden = gethash_e(self, package->pk.hidhash, name); + val visible = cdr(found_visible); + val hidden = cdr(found_hidden); + prot_sym_check(self, name, package); @@ -5702,16 +5705,16 @@ val intern_fallback(val str, val package_in) uw_throwf(error_s, lit("~a: name ~s isn't a string"), self, str, nao); if (fblist) { - val found; - val sym; + val found = gethash_e(self, package->pk.symhash, str); - if ((sym = gethash_f(self, package->pk.symhash, str, mkcloc(found))) || found) - return sym; + if (found) + return cdr(found); for (; fblist; fblist = cdr(fblist)) { val otherpkg = car(fblist); - if ((sym = gethash_f(self, otherpkg->pk.symhash, str, mkcloc(found))) || found) - return sym; + val found = gethash_e(self, otherpkg->pk.symhash, str); + if (found) + return cdr(found); } } @@ -9863,11 +9866,8 @@ val in(val seq, val item, val testfun, val keyfun) case NIL: return nil; case COBJ: - if (seq->co.cls == hash_s) { - val found; - gethash_f(self, seq, item, mkcloc(found)); - return if3(found, t, nil); - } + if (seq->co.cls == hash_s) + return tnil(gethash_e(self, seq, item)); /* fallthrough */ case CONS: case LCONS: @@ -10715,13 +10715,11 @@ val sel(val seq_in, val where_in) val newhash = make_similar_hash(seq); for (; where; where = cdr(where)) { - val found; - loc pfound = mkcloc(found); val key = car(where); - val value = gethash_f(self, seq, key, pfound); + val found = gethash_e(self, seq, key); if (found) - sethash(newhash, key, value); + sethash(newhash, key, cdr(found)); } return newhash; @@ -11597,8 +11595,8 @@ static void populate_obj_hash(val obj, struct strm_ctx *ctx) tail: if (circle_print_eligible(obj)) { if (ctx->obj_hash_prev) { - val prev_cell; - val label = gethash_f(self, ctx->obj_hash_prev, obj, mkcloc(prev_cell)); + val prev_cell = gethash_e(self, ctx->obj_hash_prev, obj); + val label = cdr(prev_cell); if (label == colon_k) uw_throwf(error_s, lit("print: unexpected duplicate object " |