diff --git a/bytecode.cpp b/bytecode.cpp index dd09eb1cf..d7de78c1c 100644 --- a/bytecode.cpp +++ b/bytecode.cpp @@ -219,20 +219,17 @@ void print_const(std::ostream& pyc_output, PycRef obj, PycModule* mod case PycObject::TYPE_DICT: { pyc_output << "{"; - PycDict::key_t keys = obj.cast()->keys(); PycDict::value_t values = obj.cast()->values(); - auto ki = keys.cbegin(); - auto vi = values.cbegin(); - if (ki != keys.cend()) { - print_const(pyc_output, *ki, mod); + auto it = values.cbegin(); + if (it != values.cend()) { + print_const(pyc_output, std::get<0>(*it), mod); pyc_output << ": "; - print_const(pyc_output, *vi, mod); - while (++ki != keys.cend()) { - ++vi; + print_const(pyc_output, std::get<1>(*it), mod); + while (++it != values.cend()) { pyc_output << ", "; - print_const(pyc_output, *ki, mod); + print_const(pyc_output, std::get<0>(*it), mod); pyc_output << ": "; - print_const(pyc_output, *vi, mod); + print_const(pyc_output, std::get<1>(*it), mod); } } pyc_output << "}"; diff --git a/pyc_sequence.cpp b/pyc_sequence.cpp index a56ca350a..29406c712 100644 --- a/pyc_sequence.cpp +++ b/pyc_sequence.cpp @@ -54,8 +54,7 @@ void PycDict::load(PycData* stream, PycModule* mod) if (key == NULL) break; val = LoadObject(stream, mod); - m_keys.push_back(key); - m_values.push_back(val); + m_values.emplace_back(std::make_tuple(key, val)); } } @@ -65,23 +64,17 @@ bool PycDict::isEqual(PycRef obj) const return false; PycRef dictObj = obj.cast(); - if (m_keys.size() != dictObj->m_keys.size()) + if (m_values.size() != dictObj->m_values.size()) return false; - auto ki1 = m_keys.cbegin(); - auto ki2 = dictObj->m_keys.cbegin(); - while (ki1 != m_keys.cend()) { - if (!(*ki1)->isEqual(*ki2)) + auto it1 = m_values.cbegin(); + auto it2 = dictObj->m_values.cbegin(); + while (it1 != m_values.cend()) { + if (!std::get<0>(*it1)->isEqual(std::get<0>(*it2))) return false; - ++ki1, ++ki2; - } - - auto vi1 = m_values.cbegin(); - auto vi2 = dictObj->m_values.cbegin(); - while (vi1 != m_values.cend()) { - if (!(*vi1)->isEqual(*vi2)) + if (!std::get<1>(*it1)->isEqual(std::get<1>(*it2))) return false; - ++vi1, ++vi2; + ++it1, ++it2; } return true; } diff --git a/pyc_sequence.h b/pyc_sequence.h index 15ed139a7..64ff66ca5 100644 --- a/pyc_sequence.h +++ b/pyc_sequence.h @@ -2,6 +2,7 @@ #define _PYC_SEQUENCE_H #include "pyc_object.h" +#include #include class PycSequence : public PycObject { @@ -54,8 +55,8 @@ class PycSet : public PycSimpleSequence { class PycDict : public PycObject { public: - typedef std::vector> key_t; - typedef std::vector> value_t; + typedef std::tuple, PycRef> item_t; + typedef std::vector value_t; PycDict(int type = TYPE_DICT) : PycObject(type) { } @@ -63,11 +64,9 @@ class PycDict : public PycObject { void load(class PycData* stream, class PycModule* mod) override; - const key_t& keys() const { return m_keys; } const value_t& values() const { return m_values; } private: - key_t m_keys; value_t m_values; }; diff --git a/pycdas.cpp b/pycdas.cpp index 1275f0070..cd7612f23 100644 --- a/pycdas.cpp +++ b/pycdas.cpp @@ -183,14 +183,9 @@ void output_object(PycRef obj, PycModule* mod, int indent, case PycObject::TYPE_DICT: { iputs(pyc_output, indent, "{\n"); - PycDict::key_t keys = obj.cast()->keys(); - PycDict::value_t values = obj.cast()->values(); - PycDict::key_t::const_iterator ki = keys.begin(); - PycDict::value_t::const_iterator vi = values.begin(); - while (ki != keys.end()) { - output_object(*ki, mod, indent + 1, flags, pyc_output); - output_object(*vi, mod, indent + 2, flags, pyc_output); - ++ki, ++vi; + for (const auto& val : obj.cast()->values()) { + output_object(std::get<0>(val), mod, indent + 1, flags, pyc_output); + output_object(std::get<1>(val), mod, indent + 2, flags, pyc_output); } iputs(pyc_output, indent, "}\n"); }