From 1fcbf4cd4b9e533f0ea262b2812d4c9ec62e2d71 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 16 Feb 2023 22:01:31 -0800 Subject: [PATCH] Keep PycSet objects marshalled from files in order too --- pyc_sequence.cpp | 15 +-------------- pyc_sequence.h | 5 ++--- tests/tokenized/test_sets.txt | 2 +- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/pyc_sequence.cpp b/pyc_sequence.cpp index ba5e8d7..9b36858 100644 --- a/pyc_sequence.cpp +++ b/pyc_sequence.cpp @@ -134,7 +134,7 @@ void PycSet::load(PycData* stream, PycModule* mod) { m_size = stream->get32(); for (int i=0; i obj) const @@ -154,16 +154,3 @@ bool PycSet::isEqual(PycRef obj) const } return true; } - -PycRef PycSet::get(int idx) const -{ - if (idx < 0) - throw std::out_of_range("Set index out of range"); - - auto it = m_values.cbegin(); - while (idx-- && it != m_values.cend()) - ++it; - if (it == m_values.cend()) - throw std::out_of_range("Set index out of range"); - return *it; -} diff --git a/pyc_sequence.h b/pyc_sequence.h index 3a97af3..e69f64e 100644 --- a/pyc_sequence.h +++ b/pyc_sequence.h @@ -3,7 +3,6 @@ #include "pyc_object.h" #include -#include class PycSequence : public PycObject { public: @@ -74,7 +73,7 @@ private: class PycSet : public PycSequence { public: - typedef std::set> value_t; + typedef std::vector> value_t; PycSet(int type = TYPE_SET) : PycSequence(type) { } @@ -83,7 +82,7 @@ public: void load(class PycData* stream, class PycModule* mod) override; const value_t& values() const { return m_values; } - PycRef get(int idx) const override; + PycRef get(int idx) const override { return m_values.at(idx); } private: value_t m_values; diff --git a/tests/tokenized/test_sets.txt b/tests/tokenized/test_sets.txt index c939d7d..f9c9631 100644 --- a/tests/tokenized/test_sets.txt +++ b/tests/tokenized/test_sets.txt @@ -1,4 +1,4 @@ a = set ( ) b = { 1 , 2 } c = { 'AB' , 'CD' } -d = { 2 , 1 , 3 , 4 } +d = { 1 , 2 , 3 , 4 }