* bug#35868: [PATCH] `memql' does not work for bignums
@ 2019-05-23 15:07 Mattias Engdegård
2019-05-30 22:01 ` Paul Eggert
0 siblings, 1 reply; 3+ messages in thread
From: Mattias Engdegård @ 2019-05-23 15:07 UTC (permalink / raw)
To: 35868
[-- Attachment #1: Type: text/plain, Size: 73 bytes --]
(memql (ash 1 100) (list (ash 1 100))) => nil
Proposed patch attached.
[-- Attachment #2: 0001-Fix-memql-for-bignums.patch --]
[-- Type: application/octet-stream, Size: 2218 bytes --]
From afe2c459cff312e8c378e8381a36110f444dcb01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Thu, 23 May 2019 17:01:27 +0200
Subject: [PATCH] Fix `memql' for bignums
* src/fns.c (Fmemql): Make `memql' work for bignums.
* test/src/fns-tests.el (test-bignum-eql): Also test `memql'.
---
src/fns.c | 34 ++++++++++++++++++++++++----------
test/src/fns-tests.el | 3 ++-
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index 6b1f7331f5..da830a9000 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1567,18 +1567,32 @@ DEFUN ("memql", Fmemql, Smemql, 2, 2, 0,
The value is actually the tail of LIST whose car is ELT. */)
(Lisp_Object elt, Lisp_Object list)
{
- if (!FLOATP (elt))
- return Fmemq (elt, list);
-
- Lisp_Object tail = list;
- FOR_EACH_TAIL (tail)
+ if (FLOATP (elt))
{
- Lisp_Object tem = XCAR (tail);
- if (FLOATP (tem) && same_float (elt, tem))
- return tail;
+ Lisp_Object tail = list;
+ FOR_EACH_TAIL (tail)
+ {
+ Lisp_Object tem = XCAR (tail);
+ if (FLOATP (tem) && same_float (elt, tem))
+ return tail;
+ }
+ CHECK_LIST_END (tail, list);
+ return Qnil;
}
- CHECK_LIST_END (tail, list);
- return Qnil;
+ else if (BIGNUMP (elt))
+ {
+ Lisp_Object tail = list;
+ FOR_EACH_TAIL (tail)
+ {
+ Lisp_Object tem = XCAR (tail);
+ if (equal_no_quit (elt, tem))
+ return tail;
+ }
+ CHECK_LIST_END (tail, list);
+ return Qnil;
+ }
+ else
+ return Fmemq (elt, list);
}
DEFUN ("assq", Fassq, Sassq, 2, 2, 0,
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 6ebab4287f..a9d4d11795 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -614,7 +614,8 @@ dot2
(should (eq x x))
(should (eql x y))
(should (equal x y))
- (should-not (eql x 0.0e+NaN))))
+ (should-not (eql x 0.0e+NaN))
+ (should (memql x (list y)))))
(ert-deftest test-bignum-hash ()
"Test that hash tables work for bignums."
--
2.20.1 (Apple Git-117)
[-- Attachment #3: Type: text/plain, Size: 1 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#35868: [PATCH] `memql' does not work for bignums
2019-05-23 15:07 bug#35868: [PATCH] `memql' does not work for bignums Mattias Engdegård
@ 2019-05-30 22:01 ` Paul Eggert
2019-06-02 13:12 ` Mattias Engdegård
0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2019-05-30 22:01 UTC (permalink / raw)
To: Mattias Engdegård; +Cc: 35868-done
[-- Attachment #1: Type: text/plain, Size: 110 bytes --]
Thanks for the bug report and fix. I installed it into master, followed
by the attached performance tweaks.
[-- Attachment #2: 0001-Improve-eq1-memql-performance.patch --]
[-- Type: text/x-patch, Size: 2226 bytes --]
From 24a58620cb8ce4aa11e2428d86e58911e7975aeb Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 30 May 2019 14:57:21 -0700
Subject: [PATCH] Improve eq1/memql performance
* src/fns.c (Fmemql, Feql): Inline to tweak performance.
---
src/fns.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index da830a9000..cb47b818f1 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1521,7 +1521,7 @@ DEFUN ("elt", Felt, Selt, 2, 2, 0,
EMACS_UINT word[WORDS_PER_DOUBLE];
};
-/* Return true if X and Y are the same floating-point value.
+/* Return true if the floats X and Y have the same value.
This looks at X's and Y's representation, since (unlike '==')
it returns true if X and Y are the same NaN. */
static bool
@@ -1567,32 +1567,32 @@ DEFUN ("memql", Fmemql, Smemql, 2, 2, 0,
The value is actually the tail of LIST whose car is ELT. */)
(Lisp_Object elt, Lisp_Object list)
{
+ Lisp_Object tail = list;
+
if (FLOATP (elt))
{
- Lisp_Object tail = list;
FOR_EACH_TAIL (tail)
{
Lisp_Object tem = XCAR (tail);
if (FLOATP (tem) && same_float (elt, tem))
return tail;
}
- CHECK_LIST_END (tail, list);
- return Qnil;
}
else if (BIGNUMP (elt))
{
- Lisp_Object tail = list;
FOR_EACH_TAIL (tail)
{
Lisp_Object tem = XCAR (tail);
- if (equal_no_quit (elt, tem))
+ if (BIGNUMP (tem)
+ && mpz_cmp (XBIGNUM (elt)->value, XBIGNUM (tem)->value) == 0)
return tail;
}
- CHECK_LIST_END (tail, list);
- return Qnil;
}
else
return Fmemq (elt, list);
+
+ CHECK_LIST_END (tail, list);
+ return Qnil;
}
DEFUN ("assq", Fassq, Sassq, 2, 2, 0,
@@ -2301,7 +2301,9 @@ DEFUN ("eql", Feql, Seql, 2, 2, 0,
if (FLOATP (obj1))
return FLOATP (obj2) && same_float (obj1, obj2) ? Qt : Qnil;
else if (BIGNUMP (obj1))
- return equal_no_quit (obj1, obj2) ? Qt : Qnil;
+ return ((BIGNUMP (obj2)
+ && mpz_cmp (XBIGNUM (obj1)->value, XBIGNUM (obj2)->value) == 0)
+ ? Qt : Qnil);
else
return EQ (obj1, obj2) ? Qt : Qnil;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#35868: [PATCH] `memql' does not work for bignums
2019-05-30 22:01 ` Paul Eggert
@ 2019-06-02 13:12 ` Mattias Engdegård
0 siblings, 0 replies; 3+ messages in thread
From: Mattias Engdegård @ 2019-06-02 13:12 UTC (permalink / raw)
To: Paul Eggert; +Cc: 35868-done
31 maj 2019 kl. 00.01 skrev Paul Eggert <eggert@cs.ucla.edu>:
>
> Thanks for the bug report and fix. I installed it into master, followed by the attached performance tweaks.
Looks fine, thank you!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-02 13:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-23 15:07 bug#35868: [PATCH] `memql' does not work for bignums Mattias Engdegård
2019-05-30 22:01 ` Paul Eggert
2019-06-02 13:12 ` Mattias Engdegård
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.