[Python-checkins] python/dist/src/Lib pickle.py,1.91,1.92

Guido van Rossum guido@python.org
2003年1月27日 22:21:57 -0500


> > ! using_setitems = (self.bin and (len(object) > 1))
> > 
> > ! if using_setitems:
> > ! write(MARK)
> > 
> > ! items = object.items()
> > for key, value in items:
> > save(key)
> > save(value)
> > ! 
> > ! if not using_setitems:
> > ! write(SETITEM)
> > ! 
> > ! if using_setitems:
> > ! write(SETITEMS)
> > 
> > dispatch[DictionaryType] = save_dict
> > --- 509,534 ----
> > write = self.write
> > save = self.save
> > + items = object.iteritems()
> > 
> > if self.bin:
> > write(EMPTY_DICT)
> > ! self.memoize(object)
> > ! if len(object) > 1:
> > ! write(MARK)
> > ! for key, value in items:
> > ! save(key)
> > ! save(value)
> > ! write(SETITEMS)
> > ! return
>> In the case where self.bin and len(object) == 1, the code looks
> like it does something different.
>> The old code would save(key) & save(value) since the for loop is
> executed. The new code doesn't execute the loop though.
>> Am I missing something?

It falls through to the next block:
 # proto 0 or len(object) < 2
 for key, value in items:
 save(key)
 save(value)
 write(SETITEM)
--Guido van Rossum (home page: http://www.python.org/~guido/)

AltStyle によって変換されたページ (->オリジナル) /