From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all Date: Mon, 22 Jan 2018 14:24:38 +0900 Message-ID: <87r2qilb3d.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1516598663 28446 195.159.176.226 (22 Jan 2018 05:24:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 22 Jan 2018 05:24:23 +0000 (UTC) Cc: monnier@iro.umontreal.ca To: 30202@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 22 06:24:19 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edUaW-0006Oe-2u for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Jan 2018 06:24:08 +0100 Original-Received: from localhost ([::1]:46619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edUcW-0001NM-Bz for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Jan 2018 00:26:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edUcP-0001Mi-Bb for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 00:26:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edUcM-00052e-8D for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 00:26:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57947) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edUcM-00052W-3Q for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 00:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1edUcL-0005Wt-Qs; Mon, 22 Jan 2018 00:26:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Jan 2018 05:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30202 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: monnier@iro.umontreal.ca Original-Received: via spool by submit@debbugs.gnu.org id=B.151659870221177 (code B ref -1); Mon, 22 Jan 2018 05:26:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Jan 2018 05:25:02 +0000 Original-Received: from localhost ([127.0.0.1]:37610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edUbN-0005VU-RL for submit@debbugs.gnu.org; Mon, 22 Jan 2018 00:25:02 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57352) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edUbM-0005Ut-AO for submit@debbugs.gnu.org; Mon, 22 Jan 2018 00:25:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edUbG-0004aT-8H for submit@debbugs.gnu.org; Mon, 22 Jan 2018 00:24:55 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:52616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1edUbG-0004aN-4z for submit@debbugs.gnu.org; Mon, 22 Jan 2018 00:24:54 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edUbE-00019Q-Pm for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 00:24:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edUbB-0004XW-LO for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 00:24:52 -0500 Original-Received: from mail-pg0-x229.google.com ([2607:f8b0:400e:c05::229]:42278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edUbB-0004Wz-F0 for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 00:24:49 -0500 Original-Received: by mail-pg0-x229.google.com with SMTP id q67so6256293pga.9 for ; Sun, 21 Jan 2018 21:24:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=ujR4ARz55y9LfsaVk7FFGVf4YfVESxmIbEFSj55eVR4=; b=HsxIwlo69Hk9qp7Kxb8ijAKYasFjkUte0w+ZolemyVtPdXoV1gWQfC2XW+bY4g42PI apRfbF/RdtgQaLUZQ88nPi1d0TgO7DAtgCnsesmDbORt9Te4NTTiEyqodShbyWQBolrO E6JE3j2OzD1sNeOOIUjHIvjubAR+nSbukVw1+XfQvBBid+7nt8YmQVRyGW2oMlSGOcEu +93cVesme3mCHGGOg9bSRCE+Nec+5gpzucb+kLYXPrUXNsPSw1EXhn4H7ninQEX5UGzV c0++TCMuxUoKXtzsGyn3Xcoy+L+lRnXmCYE98MiksXPjKbltjGY6zNvkMwtnn8zfyzhn hKYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=ujR4ARz55y9LfsaVk7FFGVf4YfVESxmIbEFSj55eVR4=; b=SlSV8AVo1lhxwdv9vyKjdQ1tgiO4w4lI5/QaDNvkU/WfCCaPDinXPJu4TvexC9LgAz it95fPQh2Zki+JRwv9EMkKLv9X46mhxe6aVwlTjM8+SBX2dAMnyCSnviI5pfY68op1as 34g8EkJ7OLgGyqK2GgA9gWvZsisNTKVcdV4ZgJjaUhN61kn/Sv2+JererrMJWsqGm6bi 7I9Q3t5KbFM8lpiWIAjcstq47pr7t55pLwJZG1QTmTqqs+ZHF/nZScvNeh1K+WN2FgdR BT+2giiBFlwu9m/ct000yY0U8kVGiBmzAu6WCwLeMRkc+w4xfbvbI78o3zDxDfnqZhXH p6xA== X-Gm-Message-State: AKwxytdTiJpe5OSIO2gfrxBk0qxc1RmDWt6ixAIa9gofMrNG7vZ47pd5 Jvlmf+A5I1E6NepwkDEelytVQ/yG X-Google-Smtp-Source: AH8x224IWILYGeh3Qoc0vGGeHZP/ubmXR4jUP6cp9ADH3kKqQ/bjjC0SeIUietyoL9ZZU8jpExNTIg== X-Received: by 10.98.204.144 with SMTP id j16mr7353063pfk.101.1516598688275; Sun, 21 Jan 2018 21:24:48 -0800 (PST) Original-Received: from calancha-pc (FL1-125-193-170-29.tky.mesh.ad.jp. [125.193.170.29]) by smtp.gmail.com with ESMTPSA id g15sm25674024pgu.52.2018.01.21.21.24.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Jan 2018 21:24:47 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:142364 Archived-At: X-Debbugs-CC: monnier@iro.umontreal.ca Severity: wishlist Hi Stefan, yesterday was added (how about to announce it in NEWS file?) the new function `assoc-delete-all', which is pretty much the same as `assq-delete-all' with `equal' instead of `eq'. How do you think below patch? IIUC, the byte compiler will carry the substitution (funcall function foo bar) into (function foo bar) so that compile code won't suffer the funcall overhead, right? * `rassq-delete-all' is also very similar, maybe it could also join the refactoring. --8<-----------------------------cut here---------------start------------->8--- commit 11e4408e9f35d4da1cf07effda63354dde44d9a6 Author: tino calancha Date: Mon Jan 22 13:57:37 2018 +0900 Code refactoring * lisp/subr.el (alist-delete-all): New defun extracted from assq-delete-all. (assoc-delete-all, assq-delete-all): Use it. diff --git a/lisp/subr.el b/lisp/subr.el index 092850a44d..d8286c0937 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -705,35 +705,33 @@ member-ignore-case (setq list (cdr list))) list) -(defun assoc-delete-all (key alist) - "Delete from ALIST all elements whose car is `equal' to KEY. +(defun alist-delete-all (key alist function) + "Delete from ALIST all elements whose car is KEY. +Keys are compared with FUNCTION. Return the modified alist. Elements of ALIST that are not conses are ignored." (while (and (consp (car alist)) - (equal (car (car alist)) key)) + (funcall function (caar alist) key)) (setq alist (cdr alist))) (let ((tail alist) tail-cdr) (while (setq tail-cdr (cdr tail)) (if (and (consp (car tail-cdr)) - (equal (car (car tail-cdr)) key)) + (funcall function (caar tail-cdr) key)) (setcdr tail (cdr tail-cdr)) (setq tail tail-cdr)))) alist) +(defun assoc-delete-all (key alist) + "Delete from ALIST all elements whose car is `equal' to KEY. +Return the modified alist. +Elements of ALIST that are not conses are ignored." + (alist-delete-all key alist #'equal)) + (defun assq-delete-all (key alist) "Delete from ALIST all elements whose car is `eq' to KEY. Return the modified alist. Elements of ALIST that are not conses are ignored." - (while (and (consp (car alist)) - (eq (car (car alist)) key)) - (setq alist (cdr alist))) - (let ((tail alist) tail-cdr) - (while (setq tail-cdr (cdr tail)) - (if (and (consp (car tail-cdr)) - (eq (car (car tail-cdr)) key)) - (setcdr tail (cdr tail-cdr)) - (setq tail tail-cdr)))) - alist) + (alist-delete-all key alist #'eq)) (defun rassq-delete-all (value alist) "Delete from ALIST all elements whose cdr is `eq' to VALUE. --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 27.0.50 (build 13, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2018-01-22 built on calancha-pc Repository revision: 9fd9d4cf63d96ba9748b9e89137575e386191c82