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

Neal Norwitz neal@metaslash.com
2003年1月27日 23:15:07 -0500


On Mon, Jan 27, 2003 at 10:33:27PM -0500, Tim Peters wrote:
> [Neal Norwitz, on save_dict() rewrite]
> > 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?
>> Guido explained this already. It makes me wonder whether I shouldn't
> duplicate that block of code, though -- the point of these rewrites was
> largely to make the code more evident, by eliminating mounds of fiddly
> little "internal" branches. I originally did duplicate the loop, but it was
> such blatant code duplication then that I nuked the first copy and let it
> fall thru instead.

I like the version you checked in. But every time I look at the code,
even after Guido pointed it out, I see the wrong flow. Time for new
eyes and/or brain.
The only way I could see the correct flow was to remove the blank
line before the else and move the code before the return into a function:
 if self.bin:
 write(EMPTY_DICT)
 self.memoize(object)
 if len(object) > 1:
 save_dict_items(items)
 return
 else: # proto 0 -- can't use EMPTY_DICT or SETITEMS
 # ...
However, I don't really think the above code is much of an improvement.
> IOW, I can't win this one <wink>.

Of course. :-)
Neal

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