diff options
author | José Fonseca <jfonseca@vmware.com> | 2014-06-20 14:09:11 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2014-06-24 16:30:34 +0100 |
commit | 9f580dbb64839281c74cb68b6872370d0756af20 (patch) | |
tree | e29d1280bb7a6b5fcf146f4ccda5ad289a54e7e9 /cli | |
parent | d9a2b264010c048a843394f87e9f75e3bb68d0a6 (diff) |
cli/pickle: More efficient tuples.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/cli_pickle.cpp | 9 | ||||
-rw-r--r-- | cli/pickle.hpp | 17 |
2 files changed, 23 insertions, 3 deletions
diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp index 4d62b1e9..6d368028 100644 --- a/cli/cli_pickle.cpp +++ b/cli/cli_pickle.cpp @@ -120,6 +120,7 @@ public: void visit(Struct *node) { if (false) { + // Structures as dictionaries writer.beginDict(); for (unsigned i = 0; i < node->sig->num_members; ++i) { writer.beginItem(node->sig->member_names[i]); @@ -128,11 +129,13 @@ public: } writer.endDict(); } else { - writer.beginTuple(); - for (unsigned i = 0; i < node->sig->num_members; ++i) { + // Structures as tuples + unsigned num_members = node->sig->num_members; + writer.beginTuple(num_members); + for (unsigned i = 0; i < num_members; ++i) { _visit(node->members[i]); } - writer.endTuple(); + writer.endTuple(num_members); } } diff --git a/cli/pickle.hpp b/cli/pickle.hpp index 59af6a7b..aaecc188 100644 --- a/cli/pickle.hpp +++ b/cli/pickle.hpp @@ -162,6 +162,23 @@ public: os.put(TUPLE); } + inline void beginTuple(unsigned length) { + if (length >= 4) { + os.put(MARK); + } + } + + inline void endTuple(unsigned length) { + static const Opcode ops[4] = { + EMPTY_TUPLE, + TUPLE1, + TUPLE2, + TUPLE3, + }; + Opcode op = length < 4 ? ops[length] : TUPLE; + os.put(op); + } + inline void writeString(const char *s, size_t length) { if (!s) { writeNone(); |