8000 Intern map keys (#381) · eb-emilio/msgpack-python@2c66689 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c66689

Browse files
authored
Intern map keys (msgpack#381)
Fixes msgpack#372.
1 parent e419cd8 commit 2c66689

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

msgpack/fallback.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ def _unpack(self, execute=EX_CONSTRUCT):
644644
key = self._unpack(EX_CONSTRUCT)
645645
if self._strict_map_key and type(key) not in (unicode, bytes):
646646
raise ValueError("%s is not allowed for map key" % str(type(key)))
647+
if not PY2 and type(key) is str:
648+
key = sys.intern(key)
647649
ret[key] = self._unpack(EX_CONSTRUCT)
648650
if self._object_hook is not None:
649651
ret = self._object_hook(ret)

msgpack/unpack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current,
192192
PyErr_Format(PyExc_ValueError, "%.100s is not allowed for map key", Py_TYPE(k)->tp_name);
193193
return -1;
194194
}
195+
if (PyUnicode_CheckExact(k)) {
196+
PyUnicode_InternInPlace(&k);
197+
}
195198
if (u->has_pairs_hook) {
196199
msgpack_unpack_object item = PyTuple_Pack(2, k, v);
197200
if (!item)

0 commit comments

Comments
 (0)
0