Skip to content

Commit

Permalink
Fixes test error + further optimization
Browse files Browse the repository at this point in the history
We can only cache string type mime data comparisons (hashable). Also
added a cache on compare_text_approximate, as profiling showed that a
hash there gives a reasonable amount of hits.
  • Loading branch information
vidartf committed Apr 20, 2017
1 parent ce8e5b7 commit 4e8b96a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions nbdime/diffing/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# an argument instead of separate functions.


@lru_cache(maxsize=1024, typed=False)
def compare_text_approximate(x, y):
# Fast cutoff when one is empty
if bool(x) != bool(y):
Expand Down Expand Up @@ -94,7 +95,15 @@ def compare_base64_strict(x, y):
return x == y


@lru_cache(maxsize=1024, typed=False)
@lru_cache(maxsize=128, typed=False)
def _compare_mimedata_strings(x, y, comp_text, comp_base64):
# Most likely base64 encoded data
if _base64.match(x):
return comp_base64(x, y)
else:
return comp_text(x, y)


def _compare_mimedata(mimetype, x, y, comp_text, comp_base64):
mimetype = mimetype.lower()

Expand All @@ -113,12 +122,7 @@ def _compare_mimedata(mimetype, x, y, comp_text, comp_base64):
# TODO: Compare binary images?
#if mimetype.startswith("image/"):
if isinstance(x, string_types) and isinstance(y, string_types):
# Most likely base64 encoded data
if _base64.match(x):
return comp_base64(x, y)
else:
return comp_text(x, y)

_compare_mimedata_strings(x, y, comp_text, comp_base64)
# Fallback to exactly equal
return x == y

Expand Down

0 comments on commit 4e8b96a

Please sign in to comment.