Changeset 6675:5350e2664296


Ignore:
Timestamp:
09/10/07 13:26:23 (6 years ago)
Author:
Robert Bradshaw <robertwb@…>
Branch:
default
Message:

Change coerce_dict to raise KeyError? (so None can be stored), slowdown elminiated

Location:
sage/structure
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sage/structure/coerce.pyx

    r6674 r6675  
    343343     
    344344    cdef coercion_maps_c(self, R, S): 
    345         homs = self._coercion_maps.get(R, S, None) 
    346         if homs is None: 
     345        try: 
     346            return self._coercion_maps.get(R, S, None) 
     347        except KeyError: 
    347348            homs = self.discover_coercion_c(R, S) 
    348349            swap = None if homs is None else (homs[1], homs[0]) 
     
    355356     
    356357    cdef get_action_c(self, R, S, op): 
    357         action = self._action_maps.get(R, S, op) 
    358         if action is None: 
     358        try: 
     359            return self._action_maps.get(R, S, op) 
     360        except KeyError: 
    359361            action = self.discover_action_c(R, S, op) 
    360362            self._action_maps.set(R, S, op, action) 
    361         return action 
     363            return action 
    362364     
    363365    cdef discover_coercion_c(self, R, S): 
     
    393395     
    394396    cdef discover_action_c(self, R, S, op): 
     397#        print "looking", R, <int>R, op, S, <int>S 
    395398     
    396399        if PY_TYPE_CHECK(S, Parent): 
  • sage/structure/coerce_dict.pyx

    r6665 r6675  
    141141        except (TypeError,ValueError): 
    142142            raise KeyError, k 
    143         value = self.get(k1, k2, k3) 
    144         if value is None: 
    145             raise KeyError, k 
    146         else: 
    147             return value 
     143        return self.get(k1, k2, k3) 
    148144             
    149145    cdef get(self, k1, k2, k3): 
     
    157153               PyList_GET_ITEM(bucket, i+2) == <PyObject*>k3: 
    158154                return <object>PyList_GET_ITEM(bucket, i+3) 
    159         return None 
     155        raise KeyError, (k1, k2, k3) 
    160156         
    161157    def __setitem__(self, k, value): 
  • sage/structure/element.pyx

    r6672 r6675  
    875875        global coercion_model 
    876876        return coercion_model.bin_op_c(left, right, mul) 
    877 #        return module_element_generic_multiply_c(left, right) 
     877        # return module_element_generic_multiply_c(left, right) 
    878878     
    879879    def __imul__(left, right): 
Note: See TracChangeset for help on using the changeset viewer.