diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-09-30 23:04:06 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-09-30 23:04:06 +0100 |
commit | e147f2af69dac2d4085a55fc9a12532639b990c4 (patch) | |
tree | d653bbae2599b8bd807998d66abdc8c25f9be7dc | |
parent | 77b08daca7df1ec04a886983c634a6e2ba545031 (diff) | |
download | swig-e147f2af69dac2d4085a55fc9a12532639b990c4.tar.gz |
Generate richcompare switch statements in sorted order
-rw-r--r-- | Source/Modules/python.cxx | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 2d2ac4f5f..9352424f2 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4073,14 +4073,16 @@ public: Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); Printf(f, " Py_XINCREF(other);\n"); } - Iterator rich_iter = First(richcompare); + List *richcompare_list = SortedKeys(richcompare, 0); + Iterator rich_iter = First(richcompare_list); if (rich_iter.item) { Printf(f, " switch (op) {\n"); for (; rich_iter.item; rich_iter = Next(rich_iter)) - Printf(f, " case %s : result = %s(self, %s); break;\n", rich_iter.key, rich_iter.item, funpack ? "other" : "tuple"); + Printf(f, " case %s : result = %s(self, %s); break;\n", rich_iter.item, Getattr(richcompare, rich_iter.item), funpack ? "other" : "tuple"); Printv(f, " default : break;\n", NIL); Printf(f, " }\n"); } + Delete(richcompare_list); Printv(f, " if (!result) {\n", NIL); Printv(f, " if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) {\n", NIL); Printv(f, " result = SwigPyObject_richcompare((SwigPyObject *)self, (SwigPyObject *)other, op);\n", NIL); |