Changeset 697

Show
Ignore:
Timestamp:
02/15/10 10:13:38 (6 months ago)
Author:
tal
Message:
The packing during serialization is optional, but on by default. It shouldn't be turned off except in the cases of deeply nested objects like Glyph. In that case, the top level object, the glyph, is packed, but the sub-objects are not packed individually. This helps with speed and the size of the serialized data.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • packages/defcon/trunk/Lib/defcon/objects/base.py

    r695 r697  
    298298    # serialization 
    299299 
    300     def serializeForUndo(self): 
     300    def serializeForUndo(self, pack=True): 
    301301        from cPickle import dumps 
    302302        import zlib 
     
    306306            customData=self.getCustomDataToSerializeForUndo() 
    307307        ) 
    308         # pickle 
    309         data = dumps(data, 0) 
    310         # compress 
    311         data = zlib.compress(data, 9) 
    312         return data 
     308        if pack: 
     309            # pickle 
     310            data = dumps(data, 0) 
     311            # compress 
     312            data = zlib.compress(data, 9) 
     313        return dict(packed=pack, data=data) 
    313314 
    314315    def getDataToSerializeForUndo(self): 
     
    323324        from cPickle import loads 
    324325        import zlib 
    325         # decompress 
    326         data = zlib.decompress(data) 
    327         # unpickle 
    328         data = loads(data) 
     326        packed = data["packed"] 
     327        data = data["data"] 
     328        if packed: 
     329            # decompress 
     330            data = zlib.decompress(data) 
     331            # unpickle 
     332            data = loads(data) 
    329333        # hold notifications 
    330334        self.holdNotifications() 
  • packages/defcon/trunk/Lib/defcon/objects/contour.py

    r696 r697  
    458458    def getDataToSerializeForUndo(self): 
    459459        data = dict( 
    460             points=[point.serializeForUndo() for point in self._points] 
     460            points=[point.serializeForUndo(pack=False) for point in self._points] 
    461461        ) 
    462462        return data 
  • packages/defcon/trunk/Lib/defcon/objects/glyph.py

    r695 r697  
    667667    def getDataToSerializeForUndo(self): 
    668668        data = dict( 
    669             contours=[contour.serializeForUndo() for contour in self._contours], 
    670             components=[component.serializeForUndo() for component in self._components], 
    671             anchors=[anchor.serializeForUndo() for anchor in self._anchors], 
     669            contours=[contour.serializeForUndo(pack=False) for contour in self._contours], 
     670            components=[component.serializeForUndo(pack=False) for component in self._components], 
     671            anchors=[anchor.serializeForUndo(pack=False) for anchor in self._anchors], 
    672672            name=self.name, 
    673673            unicodes=self.unicodes, 
    674674            width=self.width, 
    675             lib=self.lib.serializeForUndo(
     675            lib=self.lib.serializeForUndo(pack=False
    676676        ) 
    677677        return data