From e1fe5eac477bf66678a80c1e2fa3fc592c0fb453 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 28 Mar 2018 18:44:42 +0100 Subject: [PATCH] Avoid copying frozendicts It's not cheap. --- canonicaljson.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/canonicaljson.py b/canonicaljson.py index b6b1c41..89c46a1 100644 --- a/canonicaljson.py +++ b/canonicaljson.py @@ -26,7 +26,9 @@ def _default(obj): if type(obj) is frozendict: - return dict(obj) + # fishing the protected dict out of the object is a bit nasty, + # but we don't really want the overhead of copying the dict. + return obj._dict raise TypeError('Object of type %s is not JSON serializable' % obj.__class__.__name__)