ref: 29137fc29f53c66df62485ee3f7f956a5aae3041
parent: 70d8c38eef83216f3ea9ea008bb10923b58623d8
author: Ori Bernstein <[email protected]>
date: Thu Jun 7 20:22:37 EDT 2012
Remove unneded mallocs. We only care if a set is a subset; we don't actually need to compute and count the difference.
--- a/parse/bitset.c
+++ b/parse/bitset.c
@@ -113,3 +113,14 @@
for (i = 0; i < a->nchunks; i++)
a->chunks[i] &= ~b->chunks[i];
}
+
+int bsissubset(Bitset *set, Bitset *sub)
+{
+ int i;
+
+ eqsz(set, sub);
+ for (i = 0; i < set->nchunks; i++)
+ if ((sub->chunks[i] & set->chunks[i]) != set->chunks[i])
+ return 0;
+ return 1;
+}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -70,9 +70,6 @@
/* does b satisfy all the constraints of a? */
static int cstrcheck(Type *a, Type *b)
{
- Bitset *s;
- int n;
-
/* a has no cstrs to satisfy */
if (!a->cstrs)
return 1;
@@ -79,14 +76,9 @@
/* b satisfies no cstrs; only valid if a requires none */
if (!b->cstrs)
return bscount(a->cstrs) == 0;
- /* if a->cstrs \ b->cstrs == 0, then all of
- * a's constraints are satisfied. */
- s = dupbs(a->cstrs);
- bsdiff(s, b->cstrs);
- n = bscount(s);
- delbs(s);
-
- return n == 0;
+ /* if a->cstrs is a subset of b->cstrs, all of
+ * a's constraints are satisfied by b. */
+ return bsissubset(b->cstrs, a->cstrs);
}
static void loaduses(Node *n)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -233,6 +233,7 @@
void bsintersect(Bitset *a, Bitset *b);
void bsdiff(Bitset *a, Bitset *b);
int bscount(Bitset *bs);
+int bsissubset(Bitset *set, Bitset *sub);
Htab *mkht(ulong (*hash)(void *key), int (*cmp)(void *k1, void *k2));
int htput(Htab *ht, void *k, void *v);