Carl Friedrich Bolz avatar Carl Friedrich Bolz committed 24774be

an optimization: make it easy to get from a signature to the atom-signature with the same name

Comments (0)

Files changed (3)


         arity.unify(term.Number(0), heap)
     elif helper.is_term(t):
         assert isinstance(t, term.Callable)
-        functor.unify(, heap)
+        sig = t.signature()
+        atom =, signature=sig.atom_signature)
+        functor.unify(atom, heap)
         arity.unify(term.Number(t.argument_count()), heap)
     elif isinstance(t, term.Var):
         if isinstance(functor, term.Var):


     _cache = SignatureFactory()
-    _immutable_fields_ = ["name", "numargs", "factory"]
+    _immutable_fields_ = ["name", "numargs", "atom_signature", "factory"]
     def __init__(self, name, numargs, cached=False, factory=None):
         assert name is not None
         if factory is None:
             factory = self._cache
         self.factory = factory
+        if numargs:
+            atom_signature = factory.getsignature(name, 0, cached)
+        else:
+            atom_signature = self
+        self.atom_signature = atom_signature
     def eq(self, other):


     assert sig1.get_extra_engine_local("foo", e1) is None
     sig1.set_extra_engine_local("foo", 8, e2)
     assert sig1.get_extra_engine_local("foo", e2) == 8
+def test_atom_signature():
+    factory = SignatureFactory()
+    factory.register_extr_attr("foo", engine=True)
+    sig1 = factory.getsignature("a", 0)
+    assert sig1.atom_signature is sig1
+    sig2 = factory.getsignature("a", 5)
+    assert sig2.atom_signature is sig1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.