diff options
| author | Mattias Engdegård | 2022-07-10 18:02:08 +0200 |
|---|---|---|
| committer | Mattias Engdegård | 2022-07-10 18:20:37 +0200 |
| commit | cfda663282b788972c344e6733a8aa60a3e0f545 (patch) | |
| tree | 988cf3745e6057b79180a659aa4c9071acf6a1da /test/src | |
| parent | 4bab499ed0d40d4e5ca68e5a17bcf5341125f734 (diff) | |
| download | emacs-cfda663282b788972c344e6733a8aa60a3e0f545.tar.gz emacs-cfda663282b788972c344e6733a8aa60a3e0f545.zip | |
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/src')
| -rw-r--r-- | test/src/fns-tests.el | 15 |
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 @@ | |||
| 1344 | (should (equal (plist-member plist (copy-sequence "a") #'equal) | 1344 | (should (equal (plist-member plist (copy-sequence "a") #'equal) |
| 1345 | '("a" "c"))))) | 1345 | '("a" "c"))))) |
| 1346 | 1346 | ||
| 1347 | (ert-deftest fns--string-to-unibyte () | ||
| 1348 | (dolist (str '("" "a" "abc" "a\x00\x7fz" "a\xaa\xbbz ""\x80\xdd\xff")) | ||
| 1349 | (ert-info ((prin1-to-string str) :prefix "str: ") | ||
| 1350 | (should-not (multibyte-string-p str)) | ||
| 1351 | (let* ((u (string-to-unibyte str)) ; should be identity | ||
| 1352 | (m (string-to-multibyte u)) ; lossless conversion | ||
| 1353 | (uu (string-to-unibyte m))) ; also lossless | ||
| 1354 | (should-not (multibyte-string-p u)) | ||
| 1355 | (should (multibyte-string-p m)) | ||
| 1356 | (should-not (multibyte-string-p uu)) | ||
| 1357 | (should (equal str u)) | ||
| 1358 | (should (equal str uu))))) | ||
| 1359 | (should-error (string-to-unibyte "å")) | ||
| 1360 | (should-error (string-to-unibyte "ABC∀BC"))) | ||
| 1361 | |||
| 1347 | ;;; fns-tests.el ends here | 1362 | ;;; fns-tests.el ends here |