mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 10:32:56 +01:00
optimize order preservation (keep pointers to keys instead of copies); remove (unnecessary) prserveOrder flag from Stringifier::stringify()
This commit is contained in:
@@ -191,7 +191,7 @@ public:
|
||||
/// Sets a new value
|
||||
|
||||
void stringify(std::ostream& out, unsigned int indent = 0, int step = -1) const;
|
||||
/// Prints the object to out. When indent is 0, the object
|
||||
/// Prints the object to out stream. When indent is 0, the object
|
||||
/// will be printed on a single line without indentation.
|
||||
|
||||
void remove(const std::string& key);
|
||||
@@ -239,16 +239,16 @@ private:
|
||||
out << '}';
|
||||
}
|
||||
|
||||
typedef std::deque<std::string> KeyList;
|
||||
typedef Poco::DynamicStruct::Ptr StructPtr;
|
||||
typedef std::deque<const std::string*> KeyPtrList;
|
||||
typedef Poco::DynamicStruct::Ptr StructPtr;
|
||||
|
||||
const std::string& getKey(ValueMap::const_iterator& it) const;
|
||||
const Dynamic::Var& getValue(ValueMap::const_iterator& it) const;
|
||||
const std::string& getKey(KeyList::const_iterator& it) const;
|
||||
const Dynamic::Var& getValue(KeyList::const_iterator& it) const;
|
||||
const std::string& getKey(KeyPtrList::const_iterator& it) const;
|
||||
const Dynamic::Var& getValue(KeyPtrList::const_iterator& it) const;
|
||||
|
||||
ValueMap _values;
|
||||
KeyList _keys;
|
||||
KeyPtrList _keys;
|
||||
bool _preserveInsOrder;
|
||||
mutable StructPtr _pStruct;
|
||||
};
|
||||
@@ -318,9 +318,9 @@ inline const Dynamic::Var& Object::getValue(ValueMap::const_iterator& it) const
|
||||
}
|
||||
|
||||
|
||||
inline const Dynamic::Var& Object::getValue(KeyList::const_iterator& it) const
|
||||
inline const Dynamic::Var& Object::getValue(KeyPtrList::const_iterator& it) const
|
||||
{
|
||||
return _values.at(*it);
|
||||
return _values.at(**it);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,15 +37,9 @@ public:
|
||||
/// Writes a condensed string representation of the value to the output stream while preserving the insertion order.
|
||||
/// This is just a "shortcut" to stringify(any, out) with name indicating the function effect.
|
||||
|
||||
static void stringify(const Dynamic::Var& any, bool preserveInsertionOrder, std::ostream& out, unsigned int indent = 0);
|
||||
/// Writes a String representation of the value to the output stream while preserving the insertion order.
|
||||
/// When indent is 0, the generated string will be created as small as possible (condensed).
|
||||
/// When preserveInsertionOrder is true, the original string object members order will be preserved.
|
||||
/// This is a "shortcut" to stringify(any, out, indent, -1, preserveInsertionOrder).
|
||||
|
||||
static void stringify(const Dynamic::Var& any, std::ostream& out, unsigned int indent = 0, int step = -1, bool preserveInsertionOrder = false);
|
||||
/// Writes a String representation of the value to the output stream.
|
||||
/// When indent is 0, the String will be created as small as possible.
|
||||
static void stringify(const Dynamic::Var& any, std::ostream& out, unsigned int indent = 0, int step = -1);
|
||||
/// Writes a string representation of the value to the output stream.
|
||||
/// When indent is 0, the string will be created as small as possible.
|
||||
/// When preserveInsertionOrder is true, the original string object members order will be preserved;
|
||||
/// otherwise, object members are sorted by their names.
|
||||
|
||||
@@ -56,16 +50,9 @@ public:
|
||||
|
||||
inline void Stringifier::condense(const Dynamic::Var& any, std::ostream& out)
|
||||
{
|
||||
stringify(any, out, 0, -1, true);
|
||||
stringify(any, out, 0, -1);
|
||||
}
|
||||
|
||||
|
||||
inline void Stringifier::stringify(const Dynamic::Var& any, bool preserveInsertionOrder, std::ostream& out, unsigned int indent)
|
||||
{
|
||||
stringify(any, out, indent, -1, preserveInsertionOrder);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user