diff options
| author | Mattias Engdegård | 2022-03-16 15:17:19 +0100 |
|---|---|---|
| committer | Mattias Engdegård | 2022-04-04 09:49:31 +0200 |
| commit | 16ee9fa138817c061d00cf9a59d2b3f559eebfe1 (patch) | |
| tree | 7c3530dca438a692ece9ec9062931ac6da939c7a /test/src | |
| parent | 85fb2341f82d2ba687cefd21ec84d46d06834f57 (diff) | |
| download | emacs-16ee9fa138817c061d00cf9a59d2b3f559eebfe1.tar.gz emacs-16ee9fa138817c061d00cf9a59d2b3f559eebfe1.zip | |
Faster `string-lessp` for unibyte arguments
Since this function is commonly used as a sorting predicate
where it is time-critical, this is a useful optimisation.
* src/fns.c (Fstring_lessp): Add fast path for the common case
when both arguments are unibyte.
* test/src/fns-tests.el (fns-tests--string-lessp-cases)
(fns-tests-string-lessp): New test.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/fns-tests.el | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 5b252e184f0..c080c483927 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -130,6 +130,49 @@ | |||
| 130 | (should (equal [nil nil nil nil nil t t t t t] (vconcat A))) | 130 | (should (equal [nil nil nil nil nil t t t t t] (vconcat A))) |
| 131 | (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A)))))) | 131 | (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A)))))) |
| 132 | 132 | ||
| 133 | (defconst fns-tests--string-lessp-cases | ||
| 134 | '((a 97 error) | ||
| 135 | (97 "a" error) | ||
| 136 | ("abc" "abd" t) | ||
| 137 | ("abd" "abc" nil) | ||
| 138 | (abc "abd" t) | ||
| 139 | ("abd" abc nil) | ||
| 140 | (abc abd t) | ||
| 141 | (abd abc nil) | ||
| 142 | ("" "" nil) | ||
| 143 | ("" " " t) | ||
| 144 | (" " "" nil) | ||
| 145 | ("abc" "abcd" t) | ||
| 146 | ("abcd" "abc" nil) | ||
| 147 | ("abc" "abc" nil) | ||
| 148 | (abc abc nil) | ||
| 149 | ("\0" "" nil) | ||
| 150 | ("" "\0" t) | ||
| 151 | ("~" "\x80" t) | ||
| 152 | ("\x80" "\x80" nil) | ||
| 153 | ("\xfe" "\xff" t) | ||
| 154 | ("Munchen" "München" t) | ||
| 155 | ("München" "Munchen" nil) | ||
| 156 | ("München" "München" nil) | ||
| 157 | ("Ré" "Réunion" t))) | ||
| 158 | |||
| 159 | |||
| 160 | (ert-deftest fns-tests-string-lessp () | ||
| 161 | ;; Exercise both `string-lessp' and its alias `string<', both directly | ||
| 162 | ;; and in a function (exercising its bytecode). | ||
| 163 | (dolist (lessp (list #'string-lessp #'string< | ||
| 164 | (lambda (a b) (string-lessp a b)) | ||
| 165 | (lambda (a b) (string< a b)))) | ||
| 166 | (ert-info ((prin1-to-string lessp) :prefix "function: ") | ||
| 167 | (dolist (case fns-tests--string-lessp-cases) | ||
| 168 | (ert-info ((prin1-to-string case) :prefix "case: ") | ||
| 169 | (pcase case | ||
| 170 | (`(,x ,y error) | ||
| 171 | (should-error (funcall lessp x y))) | ||
| 172 | (`(,x ,y ,expected) | ||
| 173 | (should (equal (funcall lessp x y) expected))))))))) | ||
| 174 | |||
| 175 | |||
| 133 | (ert-deftest fns-tests-compare-strings () | 176 | (ert-deftest fns-tests-compare-strings () |
| 134 | (should-error (compare-strings)) | 177 | (should-error (compare-strings)) |
| 135 | (should-error (compare-strings "xyzzy" "xyzzy")) | 178 | (should-error (compare-strings "xyzzy" "xyzzy")) |