summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMattias Engdegård <mattiase@acm.org>2022-07-10 18:02:08 +0200
committerMattias Engdegård <mattiase@acm.org>2022-07-10 18:20:37 +0200
commitcfda663282b788972c344e6733a8aa60a3e0f545 (patch)
tree988cf3745e6057b79180a659aa4c9071acf6a1da /test
parent4bab499ed0d40d4e5ca68e5a17bcf5341125f734 (diff)
downloademacs-cfda663282b788972c344e6733a8aa60a3e0f545.tar.gz
Speed up string-to-unibyte
* src/character.h (str_to_unibyte): * src/character.c (str_to_unibyte): Remove. * src/fns.c (Fstring_to_unibyte): Ditch the call to str_to_unibyte and the unnecessary heap allocation. Write new, faster code. * test/src/fns-tests.el (fns--string-to-unibyte): New test.
Diffstat (limited to 'test')
-rw-r--r--test/src/fns-tests.el15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index ba56019d4cd..0119e31df11 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -1344,4 +1344,19 @@
(should (equal (plist-member plist (copy-sequence "a") #'equal)
'("a" "c")))))
+(ert-deftest fns--string-to-unibyte ()
+ (dolist (str '("" "a" "abc" "a\x00\x7fz" "a\xaa\xbbz ""\x80\xdd\xff"))
+ (ert-info ((prin1-to-string str) :prefix "str: ")
+ (should-not (multibyte-string-p str))
+ (let* ((u (string-to-unibyte str)) ; should be identity
+ (m (string-to-multibyte u)) ; lossless conversion
+ (uu (string-to-unibyte m))) ; also lossless
+ (should-not (multibyte-string-p u))
+ (should (multibyte-string-p m))
+ (should-not (multibyte-string-p uu))
+ (should (equal str u))
+ (should (equal str uu)))))
+ (should-error (string-to-unibyte "å"))
+ (should-error (string-to-unibyte "ABC∀BC")))
+
;;; fns-tests.el ends here