aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorMattias Engdegård2025-07-19 16:15:47 +0200
committerMattias Engdegård2025-07-19 16:48:11 +0200
commitf4a9673f615aa8d1fad499784fdcd11ac0ec4042 (patch)
treef0009c8133bbf89fc73d6fa10ed8f59f4ed9589d /test/src
parente9deec70dac822f2f312497c6d7a7bd6b4e648bb (diff)
downloademacs-f4a9673f615aa8d1fad499784fdcd11ac0ec4042.tar.gz
emacs-f4a9673f615aa8d1fad499784fdcd11ac0ec4042.zip
Speed up unintern, and fix symbol shorthand edge case (bug#79035)
Don't do a full lookup if the argument is a symbol, and only compute the hash index once. Fix a bug that occurred when there is another symbol whose shorthand is equal to the true name of the symbol being removed. * src/lread.c (Funintern): Rewrite for speed and correctness. (oblookup_last_bucket_number, oblookup): Remove now unused variable. * test/src/lread-tests.el (lread-unintern): New test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/lread-tests.el77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index d9b31a6c438..51c93b38e4f 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -398,4 +398,81 @@ literals (Bug#20852)."
398 (should (equal val "a\xff")) ; not "aÿ" 398 (should (equal val "a\xff")) ; not "aÿ"
399 (should-not (multibyte-string-p val)))) 399 (should-not (multibyte-string-p val))))
400 400
401(ert-deftest lread-unintern ()
402 (cl-flet ((oa-syms (oa) (let ((syms nil))
403 (mapatoms (lambda (s) (push s syms)) oa)
404 (sort syms))))
405 (let* ((oa (obarray-make))
406 (s1 (intern "abc" oa))
407 (s2 (intern "def" oa)))
408 (should-not (eq s1 'abc))
409 (should (eq (unintern "xyz" oa) nil))
410 (should (eq (unintern 'abc oa) nil))
411 (should (eq (unintern 'xyz oa) nil))
412 (should (equal (oa-syms oa) (list s1 s2)))
413 (should (eq (intern-soft "abc" oa) s1))
414 (should (eq (intern-soft "def" oa) s2))
415
416 (should (eq (unintern "abc" oa) t))
417 (should-not (intern-soft "abc" oa))
418 (should (eq (intern-soft "def" oa) s2))
419 (should (equal (oa-syms oa) (list s2)))
420
421 (should (eq (unintern s2 oa) t))
422 (should-not (intern-soft "def" oa))
423 (should (eq (oa-syms oa) nil)))
424
425 ;; with shorthand
426 (let* ((oa (obarray-make))
427 (read-symbol-shorthands '(("a·" . "ZZ•")))
428 (s1 (intern "a·abc" oa))
429 (s2 (intern "a·def" oa))
430 (s3 (intern "a·ghi" oa)))
431 (should (equal (oa-syms oa) (list s1 s2 s3)))
432 (should (equal (symbol-name s1) "ZZ•abc"))
433 (should (eq (intern-soft "ZZ•abc" oa) s1))
434 (should (eq (intern-soft "a·abc" oa) s1))
435 (should (eq (intern-soft "ZZ•def" oa) s2))
436 (should (eq (intern-soft "a·def" oa) s2))
437 (should (eq (intern-soft "ZZ•ghi" oa) s3))
438 (should (eq (intern-soft "a·ghi" oa) s3))
439
440 ;; unintern using long name
441 (should (eq (unintern "ZZ•abc" oa) t))
442 (should-not (intern-soft "ZZ•abc" oa))
443 (should-not (intern-soft "a·abc" oa))
444 (should (equal (oa-syms oa) (list s2 s3)))
445 (should (eq (intern-soft "ZZ•def" oa) s2))
446 (should (eq (intern-soft "a·def" oa) s2))
447 (should (eq (intern-soft "ZZ•ghi" oa) s3))
448 (should (eq (intern-soft "a·ghi" oa) s3))
449
450 ;; unintern using short name
451 (should (eq (unintern "a·def" oa) t))
452 (should-not (intern-soft "ZZ•def" oa))
453 (should-not (intern-soft "a·def" oa))
454 (should (equal (oa-syms oa) (list s3)))
455 (should (eq (intern-soft "ZZ•ghi" oa) s3))
456 (should (eq (intern-soft "a·ghi" oa) s3))
457
458 ;; unintern using symbol
459 (should (eq (unintern s3 oa) t))
460 (should-not (intern-soft "ZZ•ghi" oa))
461 (should-not (intern-soft "a·ghi" oa))
462 (should (eq (oa-syms oa) nil)))
463
464 ;; edge case: a symbol whose true name is another's shorthand
465 (let* ((oa (obarray-make))
466 (s1 (intern "a·abc" oa))
467 (read-symbol-shorthands '(("a·" . "ZZ•")))
468 (s2 (intern "a·abc" oa)))
469 (should (equal (oa-syms oa) (list s2 s1)))
470 (should (equal (symbol-name s1) "a·abc"))
471 (should (equal (symbol-name s2) "ZZ•abc"))
472
473 ;; unintern by symbol
474 (should (eq (unintern s1 oa) t))
475 (should (equal (oa-syms oa) (list s2))))
476 ))
477
401;;; lread-tests.el ends here 478;;; lread-tests.el ends here