Ticket #14159: trac_14159_use_cdef_get.patch

File trac_14159_use_cdef_get.patch, 2.4 KB (added by SimonKing, 7 years ago)

Use cdef get/set methods of MonoDict and TripleDict in cython modules

  • sage/structure/parent_old.pyx

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1362123171 -3600
    # Node ID 4ed99b32fd05bb4becf3535ce4a4a5444f817d59
    # Parent  1cc6aad13f0d62690736b2e6320880b0c858dcbc
    #14159: Use cdef methods to get faster access to values of a TripleDict
    
    diff --git a/sage/structure/parent_old.pyx b/sage/structure/parent_old.pyx
    a b  
    129129            self.init_coerce()
    130130        cdef object ret
    131131        try:
    132             ret = PyObject_GetItem(self._coerce_from_hash,S)
     132            ret = self._coerce_from_hash.get(S)
    133133            return ret
    134134        except KeyError:
    135135            pass
     
    158158                mor = mor * sage_type.coerce_map_from(S)
    159159           
    160160        if mor is not None:
    161             self._coerce_from_hash[S] = mor # TODO: if this is None, could it be non-None in the future?
     161            self._coerce_from_hash.set(S, mor) # TODO: if this is None, could it be non-None in the future?
    162162           
    163163        return mor
    164164       
     
    204204        try:
    205205            if self._action_hash is None: # this is because parent.__init__() does not always get called
    206206                self.init_coerce()
    207             return self._action_hash[S, op, self_on_left]
     207            return self._action_hash.get(S, op, self_on_left)
    208208        except KeyError:
    209209            pass
    210210        if HAS_DICTIONARY(self):
     
    215215            from sage.categories.action import Action
    216216            if not isinstance(action, Action):
    217217                raise TypeError, "get_action_impl must return None or an Action"
    218             self._action_hash[S, op, self_on_left] = action
     218            self._action_hash.set(S, op, self_on_left, action)
    219219        return action
    220220       
    221221    def get_action_impl(self, S, op, self_on_left):
     
    326326            self._has_coerce_map_from = MonoDict(23)
    327327        else:
    328328            try:
    329                 return self._has_coerce_map_from[S]
     329                return self._has_coerce_map_from.get(S)
    330330            except KeyError:
    331331                pass
    332332        if HAS_DICTIONARY(self):
    333333            x = self.has_coerce_map_from_impl(S)
    334334        else:
    335335            x = self.has_coerce_map_from_c_impl(S)
    336         self._has_coerce_map_from[S] = x
     336        self._has_coerce_map_from.set(S, x)
    337337        return x
    338338
    339339    def has_coerce_map_from_impl(self, S):