From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id SD7zDfQFDWeu5AAAqHPOHw:P1 (envelope-from ) for ; Mon, 14 Oct 2024 11:52:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id SD7zDfQFDWeu5AAAqHPOHw (envelope-from ) for ; Mon, 14 Oct 2024 13:52:20 +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=rmG1zhsC; 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"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1728906740; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=hJ4mwcU8KzI1U6YDIq/CcWezsLfKMx86cMwU++V9gFM=; b=qpb4NvuQhWN5dzh3VO3vYSAoedO/meZD8b9VvXeyn+fh9lmt/NJOYbpPqH4pQSVhN+LYJ7 etZTqUDCD/WE0cYYEWqLP4CrPwgF9EGylftAi4x0BEVZzQUZBaXqGJkLt1zJBTP6UyDyLs fXFJeR8jvx8+izSZiiUKsC8xKX8R6S9GtT8JrU3Oxj5jpvd8FYdjtBLwNy3bEmWWOGxpwG qIrQcYqIhU5iICFABf+hp1+RUvP2+5zLW5+z+tsmamXSsqpAZzRodqPAg1Z/Ivy8ZYHqET PmeAAlqG4Oj6NDsr9YO9IEC8eT6RF5XqFVbVwGQ9XaMeL1BldBYGnrf3E3+TAQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=sachachua-com.20230601.gappssmtp.com header.s=20230601 header.b=rmG1zhsC; 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"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1728906740; a=rsa-sha256; cv=none; b=bZmaFohV+Hwur/+eNBhMNu94L7WeTRhRaBM9aNY/931DppJaMXnOIPlfonhycYbIodcrLq d2SouqXZ4Ge4cjSbXC2YQ5/ubcVArtRLKm4OjjQfSRPiU6dJZNC4BeCZ8jWGUWUwy5XhQQ 1b+BVo4pDDqYj7dd/4zzoLz2za8jbPVwAeEur7y3+bEmCfKH1k+kf4hCKX7eDx1DiML0jF 8erdmRUDxpQRiCVqOYrW4CqYAAwsFMK4giHsrNABw/nbNKC5tqvVsO1hbOWdSiJWYOk7+M nWu9f86hixFd7D2h8PQckQggx4x5hGeCmc7FwdkWn5JpStbuZuaLwPRPV7i2/g== 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 4E534800E2 for ; Mon, 14 Oct 2024 13:52:19 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0JbZ-0005fU-0o; Mon, 14 Oct 2024 07:51:17 -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 1t0JbT-0005ez-6D for emacs-orgmode@gnu.org; Mon, 14 Oct 2024 07:51:12 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0JbN-0005wJ-Pa for emacs-orgmode@gnu.org; Mon, 14 Oct 2024 07:51:10 -0400 Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-45effbc3348so36300951cf.2 for ; Mon, 14 Oct 2024 04:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sachachua-com.20230601.gappssmtp.com; s=20230601; t=1728906663; x=1729511463; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=hJ4mwcU8KzI1U6YDIq/CcWezsLfKMx86cMwU++V9gFM=; b=rmG1zhsCLJG9ZBB7lw8ubUCNkRyu3vtGGt8mnGD4LDerxtPFSpgaqNHFLzmCfhbtqu EV63e8m3DRQ5sG/bzrLXEylxybin0QZQrY6BUwTTz3f9PBvoYlW0JKnOS3hQcu/LY4tl aTUMsV7x43yPGonbh8E9OVm0TB7Sc0Kug469EZL/ZukUL/5K8847QDik9qxMm22tc6lO LehsMVzul4EuOJSZQ39TC20uWnM4XwSRDcqM7qsreInMNW2nNHSTXgwLjsZZGt/pR5Fd Ae5vl1Ov2YnrVViZvTsmJfYj4T4eagWM+Q10LWlxu3rWpw21wLK6G4ZqxLNECY1pkcrv 8v1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728906663; x=1729511463; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hJ4mwcU8KzI1U6YDIq/CcWezsLfKMx86cMwU++V9gFM=; b=pWxvmZFbbe1QOiPfzOYvpBQhKmFVZsVft9r6dD9ZkH/ZexxhJ7ug741n1g+9omxSjv Hp4KCPwKzwjL5R3TQ1OQYUcixtdMXTobhsXOdOi6m9NoM0vAlH784kzoXM8gxTA/eu28 9UsZkIZqZOq7AMrMcmmw8dOni2UzJYMjjj/WC47a6HkXcSn2ohTWQX0qqY38u5kXp21e yDCG+oIzf00l3jHqn+mNNPuOqFFBqBxvQ0gl3Li6QGCMkPjGLPAq4SSKO0VBXeAwOYUJ /wIx9Nk6d3oqFhBo3m0sVDK0pIqPoqEHbWy5QY5d7k5B+9MQ8CtT4EK/SIKhB6QDX146 IgQA== X-Gm-Message-State: AOJu0YzpfgsyaY/10mZqRO58PUYSrAbnQX31VibgtW6pM7yJwmNS4e4W b3Fii4Kth/ry6FK1zfbYBGCYgEpAmENqhNU4ZSWvuoZnyeLjSC64V0GhsckcfDxRBKc3YJIfayM z X-Google-Smtp-Source: AGHT+IEmQfR6n0YmtLhiRcfI9bHJFwWZObwZcsW6W4Y7uMr2gcLpA42oZn1hu2+IAbUYNBftwDSddA== X-Received: by 2002:ac8:6f08:0:b0:45f:6cf:9230 with SMTP id d75a77b69052e-460584b009cmr158664631cf.45.1728906663465; Mon, 14 Oct 2024 04:51:03 -0700 (PDT) Received: from sacha-p52 ([70.55.4.235]) by smtp.googlemail.com with ESMTPSA id d75a77b69052e-460427d53bfsm43773081cf.29.2024.10.14.04.50.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:51:01 -0700 (PDT) From: Sacha Chua To: emacs-orgmode@gnu.org Subject: [PATCH] org-refile: calculate file part of the outline path outside the loop for the headings Date: Mon, 14 Oct 2024 07:50:48 -0400 Message-ID: <877caadht3.fsf@sachachua.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: none client-ip=2607:f8b0:4864:20::82f; envelope-from=sacha@sachachua.com; helo=mail-qt1-x82f.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-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -1.26 X-Spam-Score: -1.26 X-Migadu-Queue-Id: 4E534800E2 X-TUID: OP5uOoHkBUgp --=-=-= Content-Type: text/plain Hello, all! 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 files when org-refile-use-outline-path is set to 'title. The following patch let-binds that part to a variable that can be put outside the loop for the headings, making it faster in the case where refile targets include a few files with lots of headings. Does it make sense? I was wondering if I was missing some important reason for it to be inside that loop. 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-refile-calculate-file-part-of-the-outline-path-o.patch >From 85a68b44cb3ddc5eda2dfe36614fdd6fb0755f6f 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 | 89 +++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/lisp/org-refile.el b/lisp/org-refile.el index 6da5f6482..7189f91a0 100644 --- a/lisp/org-refile.el +++ b/lisp/org-refile.el @@ -338,53 +338,52 @@ defun org-refile-get-targets (and f (file-name-nondirectory f))) f nil nil) tgs)) - (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 + (org-with-wide-buffer + (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 --=-=-= Content-Type: text/plain Best regards, Sacha --=-=-=--