diff options
author | Naoki INADA <inada-n@eagle> | 2009-06-24 01:38:48 +0900 |
---|---|---|
committer | Naoki INADA <inada-n@eagle> | 2009-06-24 01:38:48 +0900 |
commit | d32b48f98f09be8c829a8d48f8d7fcdb4bd0c61e (patch) | |
tree | e6edbb1ab5973b4f647a0ab1992d9dc96779a4d5 /msgpack/unpack.h | |
parent | f2d07e5d6906567ce06d87dd21085828b3ebc1cc (diff) | |
download | msgpack-python-d32b48f98f09be8c829a8d48f8d7fcdb4bd0c61e.tar.gz |
Remove duplicated values.
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r-- | msgpack/unpack.h | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 12702d8..cc48d9c 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -21,18 +21,18 @@ #include <stack> #define MSGPACK_MAX_STACK_SIZE (1024) -#include "msgpack/unpack_define.h" +#include "unpack_define.h" using namespace std; +typedef map<string, PyObject*> str_cach_t; struct unpack_user { - stack<unsigned int> array_stack; - map<string, PyObject*> str_cache; + str_cach_t strcache; ~unpack_user() { - map<string, PyObject*>::iterator it, itend; - itend = str_cache.end(); - for (it = str_cache.begin(); it != itend; ++it) { + str_cach_t::iterator it, itend; + itend = strcache.end(); + for (it = strcache.begin(); it != itend; ++it) { Py_DECREF(it->second); } } @@ -108,35 +108,13 @@ static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* { Py_INCREF(Py_False); *o = Py_False; return 0; } static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ - if (n > 0) { - u->array_stack.push(0); - *o = PyList_New(n); - } - else { - *o = PyList_New(0); - } - return 0; -} - -static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) -{ - unsigned int &last = u->array_stack.top(); - PyList_SET_ITEM(*c, last, o); - last++; +{ *o = PyList_New(n); return 0; } - Py_ssize_t len = PyList_GET_SIZE(*c); - if (last >= len) { - u->array_stack.pop(); - } - return 0; -} +static inline int template_callback_array_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object o) +{ PyList_SET_ITEM(*c, current, o); return 0; } static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ - *o = PyDict_New(); - return 0; -} +{ *o = PyDict_New(); return 0; } static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) { @@ -150,16 +128,15 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha { if (l < 16) { string s(p, l); - map<string,PyObject*>::iterator it = u->str_cache.find(s); - if (it != u->str_cache.end()) { + str_cach_t ::iterator it = u->strcache.find(s); + if (it != u->strcache.end()) { *o = it->second; - Py_INCREF(*o); } else { *o = PyString_FromStringAndSize(p, l); - Py_INCREF(*o); - u->str_cache[s] = *o; + u->strcache[s] = *o; } + Py_INCREF(*o); } else { *o = PyString_FromStringAndSize(p, l); @@ -167,4 +144,4 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha return 0; } -#include "msgpack/unpack_template.h" +#include "unpack_template.h" |