Make timestamp search in org-entry-properties more efficient.

* lisp/org.el: (org-entry-properties) Stop scanning for timestamps if
a specific timestamp property (e.g., DEADLINE, SCHEDULED, etc.) is
requested and a match is found. Also, if a specific timestamp property
is requested, do not push non-relevant timestamps onto property list.

This change only effects org-entry-properties when a specific
timestamp is requested with the special flag, as in:

(org-entry-properties nil 'special "SCHEDULED")

Previously, even if only the SCHEDULED timestamp was requested,
org-entry-properties would parse all the timestamps in an entry. This
extra parsing could slow down the construction of agenda views,
especially with entries that contained a large number of log
items (CLOCK, state changes, etc.). The function org-entry-get,
however, is only interested in the first occurrence of the item. When
looking for a specific type of timestamp, org-entry-properties now
stops searching for timestamps after the match is found, unless the
property is "CLOCK".

Here are the relevant ELP results:

Before:

org-entry-get	     296         0.4724579999  0.0015961418
org-entry-properties 31          0.3438769999  0.0110928064

After:

org-entry-get        296         0.1447729999  0.0004890979
org-entry-properties 31          0.015765      0.0005085483
This commit is contained in:
Matt Lundin 2010-12-13 08:05:46 +00:00 committed by Carsten Dominik
parent 98015f3748
commit 4760c3b948
1 changed files with 33 additions and 27 deletions

View File

@ -1,4 +1,4 @@
;;; org.el --- Outline-based notes management and organizer ';;; org.el --- Outline-based notes management and organizer
;; Carstens outline-mode for keeping track of everything. ;; Carstens outline-mode for keeping track of everything.
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;; Free Software Foundation, Inc. ;; Free Software Foundation, Inc.
@ -13424,32 +13424,38 @@ things up because then unnecessary parsing is avoided."
(member specific (member specific
'("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED" '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
"TIMESTAMP" "TIMESTAMP_IA"))) "TIMESTAMP" "TIMESTAMP_IA")))
(while (re-search-forward org-maybe-keyword-time-regexp end t) (catch 'match
(setq key (if (match-end 1) (while (re-search-forward org-maybe-keyword-time-regexp end t)
(substring (org-match-string-no-properties 1) (setq key (if (match-end 1)
0 -1)) (substring (org-match-string-no-properties 1)
string (if (equal key clockstr) 0 -1))
(org-no-properties string (if (equal key clockstr)
(org-trim (org-no-properties
(buffer-substring (org-trim
(match-beginning 3) (goto-char (buffer-substring
(point-at-eol))))) (match-beginning 3) (goto-char
(substring (org-match-string-no-properties 3) (point-at-eol)))))
1 -1))) (substring (org-match-string-no-properties 3)
;; Get the correct property name from the key. This is 1 -1)))
;; necessary if the user has configured time keywords. ;; Get the correct property name from the key. This is
(setq key1 (concat key ":")) ;; necessary if the user has configured time keywords.
(cond (setq key1 (concat key ":"))
((not key) (cond
(setq key ((not key)
(if (= (char-after (match-beginning 3)) ?\[) (setq key
"TIMESTAMP_IA" "TIMESTAMP"))) (if (= (char-after (match-beginning 3)) ?\[)
((equal key1 org-scheduled-string) (setq key "SCHEDULED")) "TIMESTAMP_IA" "TIMESTAMP")))
((equal key1 org-deadline-string) (setq key "DEADLINE")) ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
((equal key1 org-closed-string) (setq key "CLOSED")) ((equal key1 org-deadline-string) (setq key "DEADLINE"))
((equal key1 org-clock-string) (setq key "CLOCK"))) ((equal key1 org-closed-string) (setq key "CLOSED"))
(when (or (equal key "CLOCK") (not (assoc key props))) ((equal key1 org-clock-string) (setq key "CLOCK")))
(push (cons key string) props)))) (if (and specific (equal key specific) (not (equal key "CLOCK")))
(progn
(push (cons key string) props)
;; no need to search further if match is found
(throw 'match t))
(when (or (equal key "CLOCK") (not (assoc key props)))
(push (cons key string) props))))))
) )
(when (memq which '(all standard)) (when (memq which '(all standard))