summaryrefslogtreecommitdiff
path: root/src/data.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2022-03-16 17:01:57 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2022-04-04 09:49:31 +0200
commit530f163a7f4f1f0ead119b8d3c3dd9fa882af9b2 (patch)
treeec3ea94eab8acd9dee73d3e0e21580d1611aea06 /src/data.c
parentf4833c88bbb3ca69f75e230a50bbd5edb4d5c00d (diff)
downloademacs-530f163a7f4f1f0ead119b8d3c3dd9fa882af9b2.tar.gz
emacs-530f163a7f4f1f0ead119b8d3c3dd9fa882af9b2.tar.bz2
emacs-530f163a7f4f1f0ead119b8d3c3dd9fa882af9b2.zip
Speed up comparisons between 2 fixnums
Since <, <=, > and >= have their own byte-ops, the corresponding functions are mostly used as arguments to higher-order functions. This optimisation is particularly beneficial for sorting, where the comparison function is time-critical. * src/data.c (Flss, Fgtr, Fleq, Fgeq): * src/fileio.c (Fcar_less_than_car): Fast path for calls with 2 fixnum arguments.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/data.c b/src/data.c
index 5894340aba3..f06b561dcc6 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2817,6 +2817,9 @@ DEFUN ("<", Flss, Slss, 1, MANY, 0,
usage: (< NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
+ if (nargs == 2 && FIXNUMP (args[0]) && FIXNUMP (args[1]))
+ return XFIXNUM (args[0]) < XFIXNUM (args[1]) ? Qt : Qnil;
+
return arithcompare_driver (nargs, args, ARITH_LESS);
}
@@ -2825,6 +2828,9 @@ DEFUN (">", Fgtr, Sgtr, 1, MANY, 0,
usage: (> NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
+ if (nargs == 2 && FIXNUMP (args[0]) && FIXNUMP (args[1]))
+ return XFIXNUM (args[0]) > XFIXNUM (args[1]) ? Qt : Qnil;
+
return arithcompare_driver (nargs, args, ARITH_GRTR);
}
@@ -2833,6 +2839,9 @@ DEFUN ("<=", Fleq, Sleq, 1, MANY, 0,
usage: (<= NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
+ if (nargs == 2 && FIXNUMP (args[0]) && FIXNUMP (args[1]))
+ return XFIXNUM (args[0]) <= XFIXNUM (args[1]) ? Qt : Qnil;
+
return arithcompare_driver (nargs, args, ARITH_LESS_OR_EQUAL);
}
@@ -2841,6 +2850,9 @@ DEFUN (">=", Fgeq, Sgeq, 1, MANY, 0,
usage: (>= NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
+ if (nargs == 2 && FIXNUMP (args[0]) && FIXNUMP (args[1]))
+ return XFIXNUM (args[0]) >= XFIXNUM (args[1]) ? Qt : Qnil;
+
return arithcompare_driver (nargs, args, ARITH_GRTR_OR_EQUAL);
}