From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 0GkvLbiDDWe68gAAe85BDQ:P1 (envelope-from ) for ; Mon, 14 Oct 2024 20:48:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 0GkvLbiDDWe68gAAe85BDQ (envelope-from ) for ; Mon, 14 Oct 2024 22:48:56 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=sachachua-com.20230601.gappssmtp.com header.s=20230601 header.b=M4HMNy9D; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1728938936; a=rsa-sha256; cv=none; b=sYIelAXPbv28at5Vj7x8u8UKvaS3DvKZpppNieu15LgBNFK+98GjAasmk3zZE3JQLzS5aG dZoqVoF+ng6n1+qUIrR8xbkrkYmxleDMd2b1zhMQdHKMynPAyafVuiiEGrVkQZcxOdfNiY 9vyFAlTQrtHMBTIUaEgZzRcxAoXq54KVy7FVHVo3iXDqu0GVcEwLYSgmS75tgbztMfGEyT YyrXoWiQ9r6MCoRUrF6qMAyzyZP4hkZDuQX3vv9LK0WvYXxYtHFgvt/paAMFl6HLEBBKhN eRsJ5E50FD3v0HDLg0KS3W2jLRqtkeyhGfAvTIUZv860ASz7ZYGrwwK+SdFkOA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=sachachua-com.20230601.gappssmtp.com header.s=20230601 header.b=M4HMNy9D; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1728938936; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=MxPGkXWK+/FgoNM35PcpeknD1twMKspZLT9qSapeqnw=; b=nr9aMcG2v7lc1DNd7sbh/cTWPEgaEanV94mDTsx997b2Yer9jT94QzDJ6/SPaOxQFpVhOz AO/DTMqN0JfQ83dOwhgA6/AufC+4VJt8tFJ3wADI02iER3VnOBqeUp4NTYxlj60hUSI6ux md2j2qJKT/+x4YXEzEv4p9rmfZhwtzwvIzIKt/7KoXXA2YOZqi5T/Vq2c0FthWMtkVZE3e 9wPSF3dVVn/S5gzZaQXHBXfl6e1dZ9RacUBwGu5Qc8/EZUIhBNnzf3UNTW64jwzTd52XSc 2PdQFhT4vFaNOmEUXkhwZGJA3+/BSSnMNLhJxvQiH+IL6xvaC2axyz8gHgGwsg== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 11EA81B4E7 for ; Mon, 14 Oct 2024 22:48:56 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0Ryy-0002bf-EH; Mon, 14 Oct 2024 16:48:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0Ryw-0002bN-Vh for emacs-orgmode@gnu.org; Mon, 14 Oct 2024 16:47:59 -0400 Received: from mail-qv1-xf2b.google.com ([2607:f8b0:4864:20::f2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0Ryu-0005vK-VU for emacs-orgmode@gnu.org; Mon, 14 Oct 2024 16:47:58 -0400 Received: by mail-qv1-xf2b.google.com with SMTP id 6a1803df08f44-6cbd550b648so38697206d6.0 for ; Mon, 14 Oct 2024 13:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sachachua-com.20230601.gappssmtp.com; s=20230601; t=1728938874; x=1729543674; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=MxPGkXWK+/FgoNM35PcpeknD1twMKspZLT9qSapeqnw=; b=M4HMNy9DmkX37SLAkbgD6cox2bD5VxaQnlOWuAJl4iWadvvzVEZJxwNYGqJAOSbZp4 H8KD2Yrxo0gaYbZ3Yg+8xqzi2Afh5I++GuE/ac0Z5YywQnxCllsA00hpshiwRDLE1kaS c+ykIIvxzaFqzDhnmT/P25tqM34dCtF+EcTdZ8moyjOgIQu1Hq7DS3vBygLfezYRIwKQ gf36AqpXWLQ/onicZc98vgrgPG3x61lhcsVlpLeisdaQAGV1QDpfBi6Rm9iey/HujBzN h9IqNQ/NS55f8czAnoWBd0uSaRcOeWZVtAVJ35uK2FsbP4vdD6wRmbM4tT6r+02yLtgu djhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728938874; x=1729543674; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MxPGkXWK+/FgoNM35PcpeknD1twMKspZLT9qSapeqnw=; b=vQEX6r54Xj7ae7txFiEXrKj8ClZk0uwd4g1UCLtEjY+GHaZjKfRcpT5nx3HZndFRso /BD55vRb5mFwg+LbJdzc180iUTMoVBMF/ur/SknSV2bMLCFkm4Soiy8o2X2gz6eFKcK6 yAacfWgtsfKAgxULZ0GbrWZluWZMCCeoTLkEGrx9DZ7x+2O3tPg4mXZ9r9BjgE5b5zqA Nmlm0NbDFR/btWt2KeobL6TxjQi0RnLiRoLMovdHWV0qWzwADQMoCUIOsm7H1XdQEK0+ dq6d/QyhzHRoW+YrjfFUB+acF+WLPW4RyI4VVW/D/xUGkiO9WEjG8QU0xaJExviNZt9y E23A== X-Gm-Message-State: AOJu0YyUNqBN0++FWUAjaxEUfcNWFK1IsaGZORz7e7/OaiIXBlQWWjKV TzMQK7djiL0snUFQd8WyyX4XvXJkgbijhEMrdFwE4fEU+KmouH+QGqK7Z9GHwjhXNxpw1g13NSW hDWc= X-Google-Smtp-Source: AGHT+IFpglelrTZFrDUXXXYgxnOHatLSNwl3ar2EpexdY341QVxgbnE6adHH3KeaapHYriuBizepBw== X-Received: by 2002:a05:6214:398c:b0:6cb:e6e7:5762 with SMTP id 6a1803df08f44-6cbf9cb4f87mr120534566d6.2.1728938874456; Mon, 14 Oct 2024 13:47:54 -0700 (PDT) Received: from sacha-p52 (bras-base-toroon0822w-grc-04-70-55-4-235.dsl.bell.ca. [70.55.4.235]) by smtp.googlemail.com with ESMTPSA id 6a1803df08f44-6cbe85d8b48sm49143846d6.68.2024.10.14.13.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 13:47:52 -0700 (PDT) From: Sacha Chua To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] org-refile: calculate file part of the outline path outside the loop for the headings In-Reply-To: <87y12qqz6m.fsf@localhost> References: <877caadht3.fsf@sachachua.com> <87y12qqz6m.fsf@localhost> Date: Mon, 14 Oct 2024 16:47:48 -0400 Message-ID: <87jzeapg23.fsf@sachachua.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: none client-ip=2607:f8b0:4864:20::f2b; envelope-from=sacha@sachachua.com; helo=mail-qv1-xf2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -5.35 X-Spam-Score: -5.35 X-Migadu-Queue-Id: 11EA81B4E7 X-Migadu-Scanner: mx10.migadu.com X-TUID: q04u3kiYeIhO --=-=-= Content-Type: text/plain Ihor Radchenko writes: Hello, Ihor! >> I noticed that org-refile-get-targets seems to recalculate the first >> part of the outline path for each heading, which makes it slow on large >> It feels like a pretty small change (just adding a let), but I >> have copyright assignment papers on file at the FSF just in case. > Agree. Yet, the tests are failing :) > 1 unexpected results: > FAILED test-org/refile-get-targets ((should (equal '("H1\\/foo") (org-test-with-temp-text "* H1/foo" (let (... ...) (mapcar ... ...))))) :form (equal ("H1\\/foo") ("H1")) :value nil :explanation (list-elt 0 (arrays-of-different-length 7 2 "H1\\/foo" "H1" first-mismatch-at 2))) Whoops, sorry, I forgot to run the tests. =) Now that I have done so, I realized that I accidentally deleted the (goto-char (point-min)) (setq org-outline-path-cache nil) before the loop. This patch should make that test run again. Once more with feeling! Sacha --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-refile-calculate-file-part-of-the-outline-path-o.patch >From ef843a24848203adc58aa3cfbafcb50639126921 Mon Sep 17 00:00:00 2001 From: Sacha Chua Date: Sun, 13 Oct 2024 21:30:29 -0400 Subject: [PATCH] org-refile: calculate file part of the outline path once per file * lisp/org-refile.el (org-refile-get-targets): Calculate the file part of the outline path once per file, improving the performance when org-refile-use-outline-path is set to 'title. --- lisp/org-refile.el | 85 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/lisp/org-refile.el b/lisp/org-refile.el index 6da5f6482..474706fe3 100644 --- a/lisp/org-refile.el +++ b/lisp/org-refile.el @@ -341,50 +341,51 @@ defun org-refile-get-targets (org-with-wide-buffer (goto-char (point-min)) (setq org-outline-path-cache nil) - (while (re-search-forward descre nil t) - (forward-line 0) - (let ((case-fold-search nil)) - (looking-at org-complex-heading-regexp)) - (let ((begin (point)) - (heading (match-string-no-properties 4))) - (unless (or (and - org-refile-target-verify-function - (not - (funcall org-refile-target-verify-function))) - (not heading)) - (let ((re (format org-complex-heading-regexp-format - (regexp-quote heading))) - (target - (if (not org-refile-use-outline-path) heading - (mapconcat - #'identity - (append - (pcase org-refile-use-outline-path - (`file (list + (let ((base (pcase org-refile-use-outline-path + (`file (list + (and (buffer-file-name (buffer-base-buffer)) + (file-name-nondirectory + (buffer-file-name (buffer-base-buffer)))))) + (`title (list + (or (org-get-title) (and (buffer-file-name (buffer-base-buffer)) (file-name-nondirectory - (buffer-file-name (buffer-base-buffer)))))) - (`title (list - (or (org-get-title) - (and (buffer-file-name (buffer-base-buffer)) - (file-name-nondirectory - (buffer-file-name (buffer-base-buffer))))))) - (`full-file-path - (list (buffer-file-name - (buffer-base-buffer)))) - (`buffer-name - (list (buffer-name - (buffer-base-buffer)))) - (_ nil)) - (mapcar (lambda (s) (replace-regexp-in-string - "/" "\\/" s nil t)) - (org-get-outline-path t t))) - "/")))) - (push (list target f re (org-refile-marker (point))) - tgs))) - (when (= (point) begin) - ;; Verification function has not moved point. - (end-of-line))))))) + (buffer-file-name (buffer-base-buffer))))))) + (`full-file-path + (list (buffer-file-name + (buffer-base-buffer)))) + (`buffer-name + (list (buffer-name + (buffer-base-buffer)))) + (_ nil)))) + (while (re-search-forward descre nil t) + (forward-line 0) + (let ((case-fold-search nil)) + (looking-at org-complex-heading-regexp)) + (let ((begin (point)) + (heading (match-string-no-properties 4))) + (unless (or (and + org-refile-target-verify-function + (not + (funcall org-refile-target-verify-function))) + (not heading)) + (let ((re (format org-complex-heading-regexp-format + (regexp-quote heading))) + (target + (if (not org-refile-use-outline-path) heading + (mapconcat + #'identity + (append + base + (mapcar (lambda (s) (replace-regexp-in-string + "/" "\\/" s nil t)) + (org-get-outline-path t t))) + "/")))) + (push (list target f re (org-refile-marker (point))) + tgs))) + (when (= (point) begin) + ;; Verification function has not moved point. + (end-of-line)))))))) (when org-refile-use-cache (org-refile-cache-put tgs (buffer-file-name) descre)) (setq targets (append tgs targets)))))) -- 2.43.0 --=-=-=--