[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [PATCH] Optimize org-habit-parse-todo

From: Matt Lundin
Subject: [Orgmode] [PATCH] Optimize org-habit-parse-todo
Date: Wed, 19 Jan 2011 07:39:45 -0500

* lisp/org-habit.el: (org-habit-parse-todo) Don't parse more days than

When constructing a consistency graph, org-habit (with this patch) will
stop searching for timestamps when the number of matches exceeds the
span of time displayed in the graph. This can produce a significant
speedup in agenda construction, especially for entries with many logbook
entries. Previously, org-habit would parse all logbook timestamps, even
if they numbered in the hundreds.

org-habit-parse-todo  33          0.7357430000  0.0222952424
org-habit-parse-todo  33          0.11648       0.0035296969

This patch respects the value of org-log-states-order-reversed, but
assumes that users do not frequently change its value (and thus the
order of their log entries).
 lisp/org-habit.el |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index b174a1f..a05dd1b 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -170,10 +170,18 @@ This list represents a \"habit\" for the rest of this 
                   habit-entry scheduled-repeat))
        (setq deadline (+ scheduled (- dr-days sr-days))))
       (org-back-to-heading t)
-      (while (re-search-forward "- State \"DONE\".*\\[\\([^]]+\\)\\]" end t)
-       (push (time-to-days
-              (org-time-string-to-time (match-string-no-properties 1)))
-             closed-dates))
+      (let* ((maxdays (+ org-habit-preceding-days org-habit-following-days))
+            (reversed org-log-states-order-reversed)
+            (search (if reversed 're-search-forward 're-search-backward))
+            (limit (if reversed end (point)))
+            (count 0))
+       (unless reversed (goto-char end))
+       (while (and (funcall search "- State \"DONE\".*\\[\\([^]]+\\)\\]" limit 
+                   (< count maxdays))
+         (push (time-to-days
+                (org-time-string-to-time (match-string-no-properties 1)))
+               closed-dates)
+         (setq count (1+ count))))
       (list scheduled sr-days deadline dr-days closed-dates))))
 (defsubst org-habit-scheduled (habit)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]