]> code.delx.au - gnu-emacs/commitdiff
IDNA speed up
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 28 Dec 2015 17:47:51 +0000 (18:47 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 28 Dec 2015 17:47:51 +0000 (18:47 +0100)
* puny.el (puny-encode-domain): Make the common non-IDNA case faster

lisp/net/puny.el

index 5874871a90d2f90184ed5d7f8030337f89054f3e..389a6dc270016362488567b27c8efd3ac1d400cb 100644 (file)
 (defun puny-encode-domain (domain)
   "Encode DOMAIN according to the IDNA/punycode algorith.
 For instance, \"fśf.org\" => \"xn--ff-2sa.org\"."
-  (mapconcat 'puny-encode-string (split-string domain "[.]") "."))
+  ;; The vast majority of domain names are not IDNA domain names, so
+  ;; add a check first to avoid doing unnecessary work.
+  (if (string-match "\\'[[:ascii:]]*\\'" domain)
+      domain
+    (mapconcat 'puny-encode-string (split-string domain "[.]") ".")))
 
 (defun puny-encode-string (string)
   "Encode STRING according to the IDNA/punycode algorithm.