aboutsummaryrefslogtreecommitdiffstats
path: root/src/unify.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-04-08 20:53:09 +0000
committerDavid Robillard <d@drobilla.net>2010-04-08 20:53:09 +0000
commit1f988f420ba3827941886962680f3e2ad6f01740 (patch)
tree9e89d69b1b1796491b144ba2253fda9f5226d3df /src/unify.cpp
parent55b6a3f313670d2cb13847d1f1b04fe3e4b21d63 (diff)
downloadresp-1f988f420ba3827941886962680f3e2ad6f01740.tar.gz
resp-1f988f420ba3827941886962680f3e2ad6f01740.tar.bz2
resp-1f988f420ba3827941886962680f3e2ad6f01740.zip
Exception specifiers.
More efficient constraints construction (c') in unify(). git-svn-id: http://svn.drobilla.net/resp/resp@253 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/unify.cpp')
-rw-r--r--src/unify.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/unify.cpp b/src/unify.cpp
index 3f06868..93dd78b 100644
--- a/src/unify.cpp
+++ b/src/unify.cpp
@@ -92,7 +92,7 @@ Subst::compose(const Subst& delta, const Subst& gamma)
}
/// Replace all occurrences of @a s with @a t
-void
+Constraints&
Constraints::replace(AType* s, AType* t)
{
for (Constraints::iterator c = begin(); c != end();) {
@@ -103,6 +103,7 @@ Constraints::replace(AType* s, AType* t)
substitute(c->second, s, t);
c = next;
}
+ return *this;
}
/// Unify a type constraint set (TAPL 22.4)
@@ -112,19 +113,17 @@ unify(const Constraints& constraints)
if (constraints.empty())
return Subst();
- AType* s = constraints.begin()->first;
- AType* t = constraints.begin()->second;
- Constraints cp = constraints;
- cp.erase(cp.begin());
+ Constraints::const_iterator i = constraints.begin();
+ AType* s = i->first;
+ AType* t = i->second;
+ Constraints cp(++i, constraints.end());
if (*s == *t) {
return unify(cp);
} else if (s->kind == AType::VAR && !t->contains(s)) {
- cp.replace(s, t);
- return Subst::compose(unify(cp), Subst(s, t));
+ return Subst::compose(unify(cp.replace(s, t)), Subst(s, t));
} else if (t->kind == AType::VAR && !s->contains(t)) {
- cp.replace(t, s);
- return Subst::compose(unify(cp), Subst(t, s));
+ return Subst::compose(unify(cp.replace(t, s)), Subst(t, s));
} else if (s->kind == AType::EXPR && t->kind == AType::EXPR) {
AType::iterator si = s->begin() + 1;
AType::iterator ti = t->begin() + 1;