From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 10 15:55:49 2017 Received: (at submit) by debbugs.gnu.org; 10 Feb 2017 20:55:49 +0000 Received: from localhost ([127.0.0.1]:35056 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ccIEO-0005W9-TV for submit@debbugs.gnu.org; Fri, 10 Feb 2017 15:55:49 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42529) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ccIEN-0005Vx-GC for submit@debbugs.gnu.org; Fri, 10 Feb 2017 15:55:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ccIEH-0006QI-6E for submit@debbugs.gnu.org; Fri, 10 Feb 2017 15:55:42 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:48232) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ccIEH-0006QE-2M for submit@debbugs.gnu.org; Fri, 10 Feb 2017 15:55:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccIEF-0008KD-6w for bug-gnu-emacs@gnu.org; Fri, 10 Feb 2017 15:55:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ccIEC-0006Q0-5a for bug-gnu-emacs@gnu.org; Fri, 10 Feb 2017 15:55:39 -0500 Received: from mail-io0-x230.google.com ([2607:f8b0:4001:c06::230]:33416) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ccIEB-0006Pw-Vl for bug-gnu-emacs@gnu.org; Fri, 10 Feb 2017 15:55:36 -0500 Received: by mail-io0-x230.google.com with SMTP id v96so60177309ioi.0 for ; Fri, 10 Feb 2017 12:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version; bh=QFfTy4/Gg7lebWDzOdKBM8z80ZpuqZi1fjDixkow0ts=; b=cfNj1jQP+MRUTQAhkUcedp9M5efqwFMR9Mda6DtRxR/gezrJv7YKseOsiI4Kb7ehoN 4/D6qi2xjImSRi25dv51rJ62Pvm22q2KEbBMCFft9tF4XOCjoc+huiAVwJq9vJWFa8+9 prAHXjXA5JnsOCzoz+hWSw4aIj6wXR/XBppB5h01YH7KAmZWVLvem+3c4+sFXaiP8Mxm dXlKXMMUlVO8hxLJG2sQB/XwX9vvngZBfE+Eb353gtL90C//LxmakEj9uSyoMt7/QlXZ JIYiETz8fuFPClN/QcxYCx64TN3waDz63OPb2IIvQ38boSENF7Z2nkOM1V+EbJnZwE/X 3wuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version; bh=QFfTy4/Gg7lebWDzOdKBM8z80ZpuqZi1fjDixkow0ts=; b=khXpccCl1HPNnWooDm20xWDuKa/szAlIIFV1zIRUb4iK+frkwOpCaoAG0pN8TLv21o TIf3KWfYYSPdVE2SJcEZskMvSNdIbzjjVpyaAxJAPh0eS1dTRRvKwNWHvxYOiCf043pt xKH1QHZ1miSh0txDA6YvPSemwYtUqSlDCm/wb7PRMZkXRym52JAjo30MU3OX1HDGG/FK dS8V3UGaUSTzkHoKTV9yTUScbuD1i5Z06vtKsTYUuw+I56CePrFus4ZN5M4yilC5Qh2L AbHHCUE7Efd1pn5+XFWLfCJmoP+Dyt2chGL5A7BvmRSE2Vsn+CUdRjTN7vdL5HCbPNqQ ZQ9g== X-Gm-Message-State: AMke39mxB21z3VaqFWBBO7d8z9Kh76XYZoZCrBYjEoXq1XmYj7m9cYmB6EspTIAT/9eJgw== X-Received: by 10.107.58.68 with SMTP id h65mr10737910ioa.179.1486760135158; Fri, 10 Feb 2017 12:55:35 -0800 (PST) Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id c21sm1469130iod.38.2017.02.10.12.55.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Feb 2017 12:55:34 -0800 (PST) From: npostavs@users.sourceforge.net To: bug-gnu-emacs@gnu.org Subject: [PATCH] Simplify cl-get using `plist-member' Date: Fri, 10 Feb 2017 15:56:46 -0500 Message-ID: <877f4xn4s1.fsf@users.sourceforge.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) --=-=-= Content-Type: text/plain Severity: wishlist Tags: patch I noticed cl-get and friends had on overly complicated implemententation. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Simplify-cl-get-using-plist-member.patch Content-Description: patch >From 760926c3b3bc36a8ac6854402e33d768c9e33fb1 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Fri, 5 Aug 2016 19:59:52 -0400 Subject: [PATCH] Simplify cl-get using `plist-member' * lisp/emacs-lisp/cl-extra.el (cl-get, cl-getf, cl--set-getf): Use `plist-member' instead of explicit loop. * test/lisp/emacs-lisp/cl-extra-tests.el: New tests. --- lisp/emacs-lisp/cl-extra.el | 28 +++++++------------------ test/lisp/emacs-lisp/cl-extra-tests.el | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 test/lisp/emacs-lisp/cl-extra-tests.el diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 644c35d7b3..edd14b816f 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el @@ -593,13 +593,7 @@ cl-get \n(fn SYMBOL PROPNAME &optional DEFAULT)" (declare (compiler-macro cl--compiler-macro-get) (gv-setter (lambda (store) (ignore def) `(put ,sym ,tag ,store)))) - (or (get sym tag) - (and def - ;; Make sure `def' is really absent as opposed to set to nil. - (let ((plist (symbol-plist sym))) - (while (and plist (not (eq (car plist) tag))) - (setq plist (cdr (cdr plist)))) - (if plist (car (cdr plist)) def))))) + (cl-getf (symbol-plist sym) tag def)) (autoload 'cl--compiler-macro-get "cl-macs") ;;;###autoload @@ -618,26 +612,20 @@ cl-getf ,(funcall setter `(cl--set-getf ,getter ,k ,val)) ,val))))))))) - (setplist '--cl-getf-symbol-- plist) - (or (get '--cl-getf-symbol-- tag) - ;; Originally we called cl-get here, - ;; but that fails, because cl-get has a compiler macro - ;; definition that uses getf! - (when def - ;; Make sure `def' is really absent as opposed to set to nil. - (while (and plist (not (eq (car plist) tag))) - (setq plist (cdr (cdr plist)))) - (if plist (car (cdr plist)) def)))) + (let ((val-tail (cdr-safe (plist-member plist tag)))) + (if val-tail (car val-tail) def))) ;;;###autoload (defun cl--set-getf (plist tag val) - (let ((p plist)) - (while (and p (not (eq (car p) tag))) (setq p (cdr (cdr p)))) - (if p (progn (setcar (cdr p) val) plist) (cl-list* tag val plist)))) + (let ((val-tail (cdr-safe (plist-member plist tag)))) + (if val-tail (progn (setcar val-tail val) plist) + (cl-list* tag val plist)))) ;;;###autoload (defun cl--do-remf (plist tag) (let ((p (cdr plist))) + ;; Can't use `plist-member' here because it goes to the cons-cell + ;; of TAG and we need the one before. (while (and (cdr p) (not (eq (car (cdr p)) tag))) (setq p (cdr (cdr p)))) (and (cdr p) (progn (setcdr p (cdr (cdr (cdr p)))) t)))) diff --git a/test/lisp/emacs-lisp/cl-extra-tests.el b/test/lisp/emacs-lisp/cl-extra-tests.el new file mode 100644 index 0000000000..3e2388acc6 --- /dev/null +++ b/test/lisp/emacs-lisp/cl-extra-tests.el @@ -0,0 +1,38 @@ +;;; cl-extra-tests.el --- tests for emacs-lisp/cl-extra.el -*- lexical-binding:t -*- + +;; Copyright (C) 2013-2017 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see `http://www.gnu.org/licenses/'. + +;;; Code: + +(require 'cl-lib) +(require 'ert) + +(ert-deftest cl-get () + (put 'cl-get-test 'x 1) + (put 'cl-get-test 'y nil) + (should (eq (cl-get 'cl-get-test 'x) 1)) + (should (eq (cl-get 'cl-get-test 'y :none) nil)) + (should (eq (cl-get 'cl-get-test 'z :none) :none))) + +(ert-deftest cl-getf () + (let ((plist '(x 1 y nil))) + (should (eq (cl-getf plist 'x) 1)) + (should (eq (cl-getf plist 'y :none) nil)) + (should (eq (cl-getf plist 'z :none) :none)))) + +;;; cl-extra-tests.el ends here -- 2.11.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 20 16:53:17 2017 Received: (at 25681) by debbugs.gnu.org; 20 Feb 2017 21:53:17 +0000 Received: from localhost ([127.0.0.1]:47865 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfvtV-0000RH-M9 for submit@debbugs.gnu.org; Mon, 20 Feb 2017 16:53:17 -0500 Received: from mail-it0-f46.google.com ([209.85.214.46]:38765) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfvtU-0000Qu-38; Mon, 20 Feb 2017 16:53:16 -0500 Received: by mail-it0-f46.google.com with SMTP id y135so31164870itc.1; Mon, 20 Feb 2017 13:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=H2kM8ryEFe4FZgM6Jy0Vb6VrNH4/GxLPtxpDmaBkBQE=; b=rpQ0bHOTPaOizwovYI2FIez8HaqElFhroqu0TRYdD3r98dI8EV06MKbXXKU4rMrpm9 1vAIVuQZ2DotusvtIktUBqAUD1hrofmWoUmArjaVKpM7Dm8pnKMjTALvl0mZpqYE5o60 IYYpm3gIB/fTQ0JSJI4kkpkPx5yQmt7PdRcqEc9u0n/aiYLh1iLMVYOEAQFFxgBlazXm LAvuMsxmlv9u2ldHhVMO/j2IjPDDVBqM71W1QrKoptA96mquzlqfNBGMKLD5onXFH9s+ mo1Fk7mdAzMZdFbFkxNv7qFESJOUu8hZFg8HeRXbp0r6AZHBRtYxUvntW0TXEf0cq+IH ckjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=H2kM8ryEFe4FZgM6Jy0Vb6VrNH4/GxLPtxpDmaBkBQE=; b=PqlMAxm7KdG4xsWMKa4IExUDYDXlbQrq0Z1ZOwGYiZliPNdSvLJcRcMLa72F90DTtO o3RYPBmMYhYgxUtbBsmXbyMRmoOg3I4QGbzG+kJn6ptJDujiWssIGIhM0xrzeKrZRRgj TpM0jKbfG7TUMDWiI+7f0cvgzPEBVh6CBrIpY4D2bGzvL2LtZvmhh77S9mex1pOr2873 w2nE3rNIemGAIw9FY198BFKtC2HZ5nd2ihB1xRK1gilVVhN8MdmKySPXkHHA85p+uup5 rF16PMg7pN5BTwtFHC5Wad9QaLpCteFtqm6B69SF7AWtZSmUAf0Dg+5UC9BlsNc/fLY/ GcOw== X-Gm-Message-State: AMke39nhoyZGAzDaQtvqL7DCZClgMsN54v+WHZ7S1Q/9OJwr+/cbnG3wyUqcVlsmwrpEDQ== X-Received: by 10.107.47.158 with SMTP id v30mr14412883iov.112.1487627590158; Mon, 20 Feb 2017 13:53:10 -0800 (PST) Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id d5sm6724020itd.3.2017.02.20.13.53.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Feb 2017 13:53:09 -0800 (PST) From: npostavs@users.sourceforge.net To: 25681@debbugs.gnu.org Subject: Re: bug#25681: [PATCH] Simplify cl-get using `plist-member' References: <877f4xn4s1.fsf@users.sourceforge.net> Date: Mon, 20 Feb 2017 16:54:20 -0500 In-Reply-To: <877f4xn4s1.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Fri, 10 Feb 2017 15:56:46 -0500") Message-ID: <87efysil4j.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.1 (/) X-Debbugs-Envelope-To: 25681 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) tags 25681 fixed close 25681 26.1 quit Pushed to master [1: 2f53c0c468]. 1: 2017-02-20 16:53:14 -0500 2f53c0c468561313dd9840e28371436c669153c2 Simplify cl-get using `plist-member' From unknown Fri Aug 15 14:46:46 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 21 Mar 2017 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator