diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 5faaf8cd4afc831958f972b14469e749693b1ea8..0000000000000000000000000000000000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,6 +0,0 @@ -Changelog is kept at [GitHub](https://github.com/Dronehub/minijson/releases), -here's only the changelog for the version in development - -# v2.7 - -* added support for strict ordering diff --git a/docs/changelog.md b/docs/changelog.md index ab65e4a15ccb2ceb3bf20fa3d12864ca7cb20ca4..05cc96748e5c4e050e6ad2063144074295cedb6b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,6 +1,12 @@ Changelog ========= +v2.8 +---- + +* serializing a dict without :code:`use_strict_order` won't construct a list of it's items, + allowing you to serialize large dictionaries + v2.7 ---- diff --git a/docs/usage.rst b/docs/usage.rst index 06145a55e9fb115f79c14eaa9ecd7bf265efef86..26d67c97d472c62b4036901dc8d8ab884a5677f9 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -87,5 +87,6 @@ There's also a class available for encoding. Use it like you would a normal Pyth and sort them before dumping them to binary output. By enabling this feature you guarantee that identical dicts, serialized by identical Pythons will have the exact same binary representation. - +So take care when serializing that with large dicts, :code:`use_strict_order` will construct a list +of all it's items, while serializing a normal dict won't. Only then strict order will be guaranteed. Your keys must be comparable anyway. diff --git a/minijson.pyx b/minijson.pyx index 4cc62402b8e4c24a2f60d8adc96a29e2dcef1cd2..6bd155b02e640a701249a6cfdbfae098d74c6b4f 100644 --- a/minijson.pyx +++ b/minijson.pyx @@ -514,13 +514,18 @@ cdef class MiniJSONEncoder: cio.write(b'\x12') cio.write(STRUCT_L.pack(length)) length = 5 - items = list(data.items()) if self.use_strict_order: + items = list(data.items()) items.sort() - for field_name, elem in items: - cio.write(bytearray([len(field_name)])) - cio.write(field_name.encode('utf-8')) - length += self.dump(elem, cio) + for field_name, elem in items: + cio.write(bytearray([len(field_name)])) + cio.write(field_name.encode('utf-8')) + length += self.dump(elem, cio) + else: + for field_name, elem in data.items(): + cio.write(bytearray([len(field_name)])) + cio.write(field_name.encode('utf-8')) + length += self.dump(elem, cio) return length else: if length <= 0xF: @@ -537,13 +542,16 @@ cdef class MiniJSONEncoder: cio.write(b'\x13') cio.write(STRUCT_L.pack(length)) offset = 5 - - items = list(data.items()) if self.use_strict_order: + items = list(data.items()) items.sort() - for key, value in items: - offset += self.dump(key, cio) - offset += self.dump(value, cio) + for key, value in items: + offset += self.dump(key, cio) + offset += self.dump(value, cio) + else: + for key, value in data.items(): + offset += self.dump(key, cio) + offset += self.dump(value, cio) return offset else: v = self.default(data) diff --git a/setup.cfg b/setup.cfg index 64b684abd92d8b9ac2d8aab0a358ae6b992fe0c0..8a68a91442f4dcfa47fc75449b016eb792878128 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ # coding: utf-8 [metadata] -version = 2.7 +version = 2.8 name = minijson long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8