commit 38ae28d95b58e9fb86a3495a2dda3e5de254c4fc parent a86afc14e20ec7287c2b37f5b64318c209c9bbd3 Author: Iqbal Ansari <iqbalansari02@yahoo.com> Date: Mon, 11 Jun 2018 21:08:05 +0530 Cache results of imagemagick support check for a format Diffstat:
M | emojify.el | | | 22 | +++++++++++++++++++--- |
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/emojify.el b/emojify.el @@ -922,6 +922,23 @@ This returns nil if the emojis between BEG and END do not fall in region." (goto-char beg) (background-color-at-point)))) +(defvar emojify--imagemagick-support-cache (ht-create)) + +(defun emojify--imagemagick-supports-p (format) + "Check if imagemagick support given FORMAT. + +This function caches the result of the check since the naive check + + (memq format (imagemagick-types)) + +can be expensive if imagemagick-types returns a large list, this is +especially problematic since this check is potentially called during +very redisplay. See https://github.com/iqbalansari/emacs-emojify/issues/41" + (when (fboundp 'imagemagick-types) + (when (equal (ht-get emojify--imagemagick-support-cache format 'unset) 'unset) + (ht-set emojify--imagemagick-support-cache format (memq format (imagemagick-types)))) + (ht-get emojify--imagemagick-support-cache format))) + (defun emojify--get-image-display (data buffer beg end &optional target) "Get the display text property to display the emoji as an image. @@ -939,9 +956,8 @@ other different display constructs, for now this works." (create-image image-file ;; use imagemagick if available and supports PNG images ;; (allows resizing images) - (when (and (fboundp 'imagemagick-types) - (memq image-type (imagemagick-types))) - 'imagemagick) + (when (emojify--imagemagick-supports-p image-type) + 'imagemagick) nil :ascent 'center :heuristic-mask t