From 3e059f76d7621d54c8d33e40d5e306d85e8d7e09 Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Fri, 22 Aug 2014 11:40:49 -0700 Subject: [PATCH] PYTHON-346 - Optimize decoding of most types. This change provides perf improvements for decoding most types in pure python. Like the previous changes for encoding, the biggest improvements are seen decoding BSON arrays to python lists - over 150% using pypy. --- bson/__init__.py | 186 +++++++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 88 deletions(-) diff --git a/bson/__init__.py b/bson/__init__.py index f9a9125b2..f9a1bb8c9 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -24,6 +24,8 @@ import struct import sys import uuid +from codecs import utf_8_decode as _utf_8_decode + from bson.binary import (Binary, OLD_UUID_SUBTYPE, JAVA_LEGACY, CSHARP_LEGACY) from bson.bsonint64 import BSONInt64 @@ -58,8 +60,6 @@ EPOCH_AWARE = datetime.datetime.fromtimestamp(0, utc) EPOCH_NAIVE = datetime.datetime.utcfromtimestamp(0) EMPTY = b"" -ZERO = b"\x00" -ONE = b"\x01" BSONNUM = b"\x01" # Floating point BSONSTR = b"\x02" # UTF-8 string @@ -83,54 +83,49 @@ BSONMIN = b"\xFF" # Min key BSONMAX = b"\x7F" # Max key +_UNPACK_FLOAT = struct.Struct("