summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-01-17 21:27:02 (GMT)
committerGuido van Rossum <guido@python.org>2001-01-17 21:27:02 (GMT)
commit2ffbf6b1125ca3c2a296e479af8b982854311600 (patch)
tree7642bddcd61c7ef3383109e62a116b46ae3e3bbc /Modules
parenta99202a017b69f176c27a4f2cee222a9b4fa9a11 (diff)
downloadcpython-2ffbf6b1125ca3c2a296e479af8b982854311600.zip
cpython-2ffbf6b1125ca3c2a296e479af8b982854311600.tar.gz
cpython-2ffbf6b1125ca3c2a296e479af8b982854311600.tar.bz2
Deal properly (?) with comparing recursive datastructures.
- Use the compare nesting level and in-progress dictionary properly in PyObject_RichCompare(). - Change the in-progress code to use static variables instead of globals (both the nesting level and the key for the thread dict were globals but have no reason to be globals; the key can even be a function-static variable in get_inprogress_dict()). - Rewrote try_rich_to_3way_compare() to benefit from the similarity of the three cases, making it table-driven. - In try_rich_to_3way_compare(), test for EQ before LT and GT. This turns out essential when comparing recursive UserList instances; with the old code, these would recurse into rich comparison three times for each nesting level up to NESTING_LIMIT/2, making the total number of calls in the order of 3**(NESTING_LIMIT/2)! NOTE: I'm not 100% comfortable with this. It works for the standard test suite (which compares a few trivial recursive data structures only), but I'm not sure that the in-progress dictionary is used properly by the rich comparison code. Jeremy suggested that maybe the operation should be included in the dict. Currently I presume that objects in the dict are equal unless proven otherwise, and I set the outcome for the rich comparison accordingly: true for operators EQ, LE, GE, and false for the other three. But Jeremy seems to think that there may be counter-examples where this doesn't do the right thing.
Diffstat (limited to 'Modules')
0 files changed, 0 insertions, 0 deletions