提交 45715e20 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Make a separate merge_signature method.

上级 843e2b32
...@@ -450,6 +450,9 @@ class Constant(Variable): ...@@ -450,6 +450,9 @@ class Constant(Variable):
def signature(self): def signature(self):
return (self.type, self.data) return (self.type, self.data)
def merge_signature(self):
return self.signature()
def __str__(self): def __str__(self):
if self.name is not None: if self.name is not None:
return self.name return self.name
......
...@@ -499,7 +499,7 @@ class MergeFeature(object): ...@@ -499,7 +499,7 @@ class MergeFeature(object):
"""Check if a constant can be merged, and queue that replacement""" """Check if a constant can be merged, and queue that replacement"""
if id(c) in self.seen_constants: if id(c) in self.seen_constants:
return return
sig = c.signature() sig = c.merge_signature()
other_c = self.const_sig_inv.get(sig, None) other_c = self.const_sig_inv.get(sig, None)
if other_c is not None: if other_c is not None:
# multiple names will clobber each other.. # multiple names will clobber each other..
......
...@@ -627,8 +627,13 @@ if (py_%(name)s == NULL) { %(freefunc)s(%(name)s); } ...@@ -627,8 +627,13 @@ if (py_%(name)s == NULL) { %(freefunc)s(%(name)s); }
class CDataTypeConstant(graph.Constant): class CDataTypeConstant(graph.Constant):
def signature(self): def merge_signature(self):
# We can't check if certain constants are equal or not so just # We don't want to merge constants that don't point to the
# assume they are all unequal. # same object.
return id(self.data) return id(self.data)
def signature(self):
# There is no way to put the data in the signature, so we
# don't even try
return (self.type,)
CDataType.Constant = CDataTypeConstant CDataType.Constant = CDataTypeConstant
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论