diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-02-14 07:22:16 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-02-14 07:22:16 -0800 |
commit | ee7866ae60fe4357bbcd453dbfdf5a90528dda7b (patch) | |
tree | aa53042bc2d2076fd8d32d3c80400cd977a483c1 | |
parent | 8c25a6210a1fc44901fd6ebf7fb3f63c0ca5eec0 (diff) | |
download | txr-ee7866ae60fe4357bbcd453dbfdf5a90528dda7b.tar.gz txr-ee7866ae60fe4357bbcd453dbfdf5a90528dda7b.tar.bz2 txr-ee7866ae60fe4357bbcd453dbfdf5a90528dda7b.zip |
gethash_c: review uses and improve or replace.
* eval.c (env_fbind, env_vbind, reg_symacro): Use gethash_l
instead of gethash_c to eliminate repeated cdr operations
on the same cell.
* hash.c (sethash): Since new_p is never used, eliminated it
and use nulloc.
(group_reduce): Use gethash_l instead of gethash_c.
* lib.c (obj_init): Replace rplacd(gethash_c(...)) pattern
whose return value is not used with with sethash. We lose some
diagnosability here since sethash doesn't take a "self"
argument.
(obj_print_impl, obj_hash_merge): Use gethash_l instead of
gethash_c.
* parser.y (ensure_parser, parser_circ_def, get_visible_syms,
rlset): Use gethash_l instead of gethash_c.
-rw-r--r-- | eval.c | 18 | ||||
-rw-r--r-- | hash.c | 15 | ||||
-rw-r--r-- | lib.c | 15 | ||||
-rw-r--r-- | parser.c | 16 | ||||
-rw-r--r-- | parser.y | 3 |
5 files changed, 32 insertions, 35 deletions
@@ -175,11 +175,11 @@ val env_fbind(val env, val sym, val fun) cell = acons_new_c(sym, nulloc, mkloc(env->e.fbindings, env)); return rplacd(cell, fun); } else { - val hcell = gethash_c(self, top_fb, sym, nulloc); - val cell = cdr(hcell); + loc pcdr = gethash_l(self, top_fb, sym, nulloc); + val cell = deref(pcdr); if (cell) return rplacd(cell, fun); - return sys_rplacd(hcell, cons(sym, fun)); + return set(pcdr, cons(sym, fun)); } } @@ -193,11 +193,11 @@ val env_vbind(val env, val sym, val obj) cell = acons_new_c(sym, nulloc, mkloc(env->e.vbindings, env)); return rplacd(cell, obj); } else { - val hcell = gethash_c(self, top_vb, sym, nulloc); - val cell = cdr(hcell); + loc pcdr = gethash_l(self, top_vb, sym, nulloc); + val cell = deref(pcdr); if (cell) return rplacd(cell, obj); - return sys_rplacd(hcell, cons(sym, obj)); + return set(pcdr, cons(sym, obj)); } } @@ -5823,13 +5823,13 @@ void reg_var(val sym, val val) static void reg_symacro(val sym, val form) { - val cell = gethash_c(lit("internal initialization"), top_smb, sym, nulloc); - val binding = cdr(cell); + loc pcdr = gethash_l(lit("internal initialization"), top_smb, sym, nulloc); + val binding = deref(pcdr); if (binding) rplacd(binding, form); else - rplacd(cell, cons(sym, form)); + set(pcdr, cons(sym, form)); } static val if_fun(val cond, val then, val alt) @@ -830,8 +830,7 @@ val gethash_n(val hash, val key, val notfound_val) val sethash(val hash, val key, val value) { val self = lit("sethash"); - val new_p; - rplacd(gethash_c(self, hash, key, mkcloc(new_p)), value); + rplacd(gethash_c(self, hash, key, nulloc), value); return value; } @@ -1258,24 +1257,24 @@ val group_reduce(val hash, val by_fun, val reduce_fun, val seq, val v = vecref(seq, num_fast(i)); val key = funcall1(by_fun, v); val new_p; - val cell = gethash_c(self, hash, key, mkcloc(new_p)); + loc pcdr = gethash_l(self, hash, key, mkcloc(new_p)); if (new_p) - rplacd(cell, funcall2(reduce_fun, initval, v)); + set(pcdr, funcall2(reduce_fun, initval, v)); else - rplacd(cell, funcall2(reduce_fun, cdr(cell), v)); + set(pcdr, funcall2(reduce_fun, deref(pcdr), v)); } } else { for (; seq; seq = cdr(seq)) { val v = car(seq); val key = funcall1(by_fun, v); val new_p; - val cell = gethash_c(self, hash, key, mkcloc(new_p)); + loc pcdr = gethash_l(self, hash, key, mkcloc(new_p)); if (new_p) - rplacd(cell, funcall2(reduce_fun, initval, v)); + set(pcdr, funcall2(reduce_fun, initval, v)); else - rplacd(cell, funcall2(reduce_fun, cdr(cell), v)); + set(pcdr, funcall2(reduce_fun, deref(pcdr), v)); } } @@ -10909,8 +10909,7 @@ static void obj_init(void) /* nil can't be interned because it's not a SYM object; it works as a symbol because the nil case is handled by symbol-manipulating function. */ - rplacd(gethash_c(self, user_package->pk.symhash, - nil_string, nulloc), nil); + sethash(user_package->pk.symhash, nil_string, nil); /* t can't be interned, because intern needs t in order to do its job. */ t = cdr(rplacd(gethash_c(self, user_package->pk.symhash, @@ -11234,19 +11233,19 @@ val obj_print_impl(val obj, val out, val pretty, struct strm_ctx *ctx) val ret = obj; if (ctx && circle_print_eligible(obj)) { - val cell = gethash_c(self, ctx->obj_hash, obj, nulloc); - val label = cdr(cell); + loc pcdr = gethash_l(self, ctx->obj_hash, obj, nulloc); + val label = deref(pcdr); if (label == t) { val counter = succ(ctx->counter); ctx->counter = counter; - rplacd(cell, counter); + set(pcdr, counter); format(out, lit("#~s="), counter, nao); } else if (integerp(label)) { format(out, lit("#~s#"), label, nao); return ret; } else if (!label) { - rplacd(cell, colon_k); + set(pcdr, colon_k); } } @@ -11681,9 +11680,9 @@ static void obj_hash_merge(val parent_hash, val child_hash) for (iter = hash_begin(child_hash); (cell = hash_next(iter));) { val new_p; - val pcell = gethash_c(self, parent_hash, car(cell), mkcloc(new_p)); + loc pcdr = gethash_l(self, parent_hash, car(cell), mkcloc(new_p)); if (new_p) - rplacd(pcell, cdr(cell)); + set(pcdr, cdr(cell)); else uw_throwf(error_s, lit("~a: unexpected duplicate object " "(internal error?)"), self, nao); @@ -175,11 +175,11 @@ static parser_t *get_parser_impl(val self, val parser) static val ensure_parser(val stream) { - val cell = gethash_c(lit("internal error"), stream_parser_hash, stream, nulloc); - val pars = cdr(cell); + loc pcdr = gethash_l(lit("internal error"), stream_parser_hash, stream, nulloc); + val pars = deref(pcdr); if (pars) return pars; - return sys_rplacd(cell, parser(stream, one)); + return set(pcdr, parser(stream, one)); } static void pushback_token(parser_t *p, struct yy_token *tok) @@ -390,12 +390,12 @@ void parser_circ_def(parser_t *p, val num, val expr) { val new_p = nil; - val cell = gethash_c(lit("parser"), p->circ_ref_hash, num, mkcloc(new_p)); + loc pcdr = gethash_l(lit("parser"), p->circ_ref_hash, num, mkcloc(new_p)); - if (!new_p && cdr(cell) != unique_s) + if (!new_p && deref(pcdr) != unique_s) yyerrorf(p->scanner, lit("duplicate #~s= def"), num, nao); - rplacd(cell, expr); + set(pcdr, expr); } } @@ -743,9 +743,9 @@ static val get_visible_syms(val package, int include_fallback) val fcell; val new_p; while ((fcell = hash_next(hiter))) { - val scell = gethash_c(lit("listener"), symhash, car(fcell), mkcloc(new_p)); + loc pcdr = gethash_l(lit("listener"), symhash, car(fcell), mkcloc(new_p)); if (new_p) - rplacd(scell, cdr(fcell)); + set(pcdr, cdr(fcell)); } } return hash_values(symhash); @@ -1628,8 +1628,7 @@ static val rlviable(val form) val rlset(val form, val info) { if (rlviable(form)) { - val cell = gethash_c(lit("rlcp"), form_to_ln_hash, form, nulloc); - loc place = cdr_l(cell); + loc place = gethash_l(lit("rlcp"), form_to_ln_hash, form, nulloc); if (nilp(deref(place))) set(place, info); } |