[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[mhc:00530] Re: スピード狂への道
>> On Fri, 21 Apr 2000 21:45:13 +0900
>> 「土」== tsuchiya@xxxxxxxxxxxxxxxxxxxxxxx (TSUCHIYA Masatoshi) said as follows:
土> mhc を高速化するべく小細工を始めました。
小細工その2。(ddate-days) や (ddate-ww) が時間を食っていそうだなぁ、と
思ったので、計算結果を cache するようにしてみました。
Index: mhc-date.el
===================================================================
RCS file: /home/tsuchiya/CVS/projects/mhc/mhc-date.el,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 mhc-date.el
--- mhc-date.el 2000/04/18 00:16:25 1.1.1.1
+++ mhc-date.el 2000/04/21 14:04:49
@@ -15,7 +15,7 @@
;;
;; 1999-04-30 corresponds to (1999 4 30)
;;
-;; ddate is also simple. It expresses a time by a list of integer.
+;; dtime is also simple. It expresses a time by a list of integer.
;; for example:
;;
;; 12:30 (12 30)
@@ -111,6 +111,8 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ddate
+(defvar ddate-cache-obarray (make-vector 1023 0))
+
;;
;; create new object, access method to each element.
;;
@@ -199,15 +201,19 @@
(defun ddate-yy (ddate) (nth 0 ddate))
(defun ddate-mm (ddate) (nth 1 ddate))
(defun ddate-dd (ddate) (nth 2 ddate))
+
(defun ddate-ww (ddate)
- ;; (0:Sun, 2:Mon, ... , 6:Sat)
- (let ((xx (1- (ddate-yy ddate))))
- (% (+ (ddate-day-of-yy ddate)
- (* xx 365)
- (/ xx 4)
- (/ xx -100)
- (/ xx 400))
- 7)))
+ (let ((symbol (intern (ddate-to-s ddate) ddate-cache-obarray)))
+ (or (get symbol 'ddate-ww)
+ (put symbol 'ddate-ww
+ ;; (0:Sun, 2:Mon, ... , 6:Sat)
+ (let ((xx (1- (ddate-yy ddate))))
+ (% (+ (ddate-day-of-yy ddate)
+ (* xx 365)
+ (/ xx 4)
+ (/ xx -100)
+ (/ xx 400))
+ 7))))))
(defun ddate-oo (ddate)
(/ (1- (ddate-dd ddate)) 7))
@@ -414,24 +420,30 @@
;; ; 1994-7-1 is the 182nd day of the year.
;;
(defun ddate-day-of-yy (ddate)
- (let (yy mm dd xx)
- (setq yy (ddate-yy ddate) mm (ddate-mm ddate) dd (ddate-dd ddate)
- xx (if (and (ddate-leap-year-p yy) (> mm 2)) 1 0))
- (- (+ dd (* (1- mm) 31) xx)
- (nth (1- mm) '(0 0 3 3 4 4 5 5 5 6 6 7)))))
+ (let ((symbol (intern (ddate-to-s ddate) ddate-cache-obarray)))
+ (or (get symbol 'ddate-day-of-yy)
+ (put symbol 'ddate-day-of-yy
+ (let (yy mm dd xx)
+ (setq yy (ddate-yy ddate) mm (ddate-mm ddate) dd (ddate-dd ddate)
+ xx (if (and (ddate-leap-year-p yy) (> mm 2)) 1 0))
+ (- (+ dd (* (1- mm) 31) xx)
+ (nth (1- mm) '(0 0 3 3 4 4 5 5 5 6 6 7))))))))
;;
;; days from 1970-01-01
;;
(defun ddate-days (ddate)
- (let ((xx (1- (ddate-yy ddate))))
- (- (+ (ddate-day-of-yy ddate)
- (* xx 365)
- (/ xx 4)
- (/ xx -100)
- (/ xx 400))
- 719163)))
+ (let ((symbol (intern (ddate-to-s ddate) ddate-cache-obarray)))
+ (or (get symbol 'ddate-days)
+ (put symbol 'ddate-days
+ (let ((xx (1- (ddate-yy ddate))))
+ (- (+ (ddate-day-of-yy ddate)
+ (* xx 365)
+ (/ xx 4)
+ (/ xx -100)
+ (/ xx 400))
+ 719163))))))
;;
;; check if date is the last week of the month.
と言っても、4ヶ月くらいの予定を見たときに、0.5 秒くらい変わるだけなん
ですけど。
--
土屋 雅稔 ( TSUCHIYA Masatoshi )
http://www-nagao.kuee.kyoto-u.ac.jp/member/tsuchiya/