[uim-commit] r1274 - in trunk: test uim

yamaken at freedesktop.org yamaken at freedesktop.org
Mon Aug 22 16:10:59 EST 2005


Author: yamaken
Date: 2005-08-21 23:10:51 -0700 (Sun, 21 Aug 2005)
New Revision: 1274

Modified:
   trunk/test/test-uim-util.scm
   trunk/uim/uim-util.c
Log:
* uim/uim-util.c
  - (iterate_lists): Fix the fast path case permanently disabled. This
    fix only affects about performance in single-list cases. Former
    codes are slow, but safe.
* test/test-uim-util.scm
  - (test iterate-lists): Add some tests for single-list cases, and
    single-null-list, multiple-null-list cases. All tests are passed


Modified: trunk/test/test-uim-util.scm
===================================================================
--- trunk/test/test-uim-util.scm	2005-08-22 05:56:08 UTC (rev 1273)
+++ trunk/test/test-uim-util.scm	2005-08-22 06:10:51 UTC (rev 1274)
@@ -29,7 +29,7 @@
 ;;; SUCH DAMAGE.
 ;;;;
 
-;; This file is tested with revision 816 of new repository
+;; This file is tested with revision 1274 of new repository
 
 (use test.unit)
 
@@ -269,6 +269,32 @@
    (assert-equal "2147483647" (uim '(digit->string 2147483647))))
 
   ("test iterate-lists"
+   ;; single list cases (fast path)
+   (assert-equal '(4 3 2 1 0)
+		 (uim '(iterate-lists (lambda (state elms)
+					(if (null? elms)
+					    (cons #t state)
+					    (cons #f (cons (car elms)
+							   state))))
+				      ()
+				      '((0 1 2 3 4)))))
+   (assert-equal '()
+		 (uim '(iterate-lists (lambda (state elms)
+					(if (null? elms)
+					    (cons #t state)
+					    (cons #f (cons (car elms)
+							   state))))
+				      ()
+				      '(()))))
+   (assert-equal 'empty
+		 (uim '(iterate-lists (lambda (state elms)
+					(if (null? elms)
+					    (cons #t state)
+					    (cons #f (cons (car elms)
+							   state))))
+				      'empty
+				      '(()))))
+   ;; multiple lists cases (normal path)
    (assert-equal '(("o" . "O") ("l" . "L") ("l" . "L") ("e" . "E") ("h" . "H"))
 		 (uim '(iterate-lists (lambda (state elms)
 					(if (null? elms)
@@ -277,7 +303,34 @@
 							   state))))
 				      ()
 				      '(("h" "e" "l" "l" "o")
-					("H" "E" "L" "L" "O" "!"))))))
+					("H" "E" "L" "L" "O" "!")))))
+   (assert-equal '(("o" "O" 4) ("l" "L" 3) ("l" "L" 2) ("e" "E" 1) ("h" "H" 0))
+		 (uim '(iterate-lists (lambda (state elms)
+					(if (null? elms)
+					    (cons #t state)
+					    (cons #f (cons elms state))))
+				      ()
+				      '(("h" "e" "l" "l" "o")
+					("H" "E" "L" "L" "O" "!")
+					(0 1 2 3 4)))))
+   (assert-equal ()
+		 (uim '(iterate-lists (lambda (state elms)
+					(if (null? elms)
+					    (cons #t state)
+					    (cons #f (cons elms state))))
+				      ()
+				      '(("h" "e" "l" "l" "o")
+					()
+					(0 1 2 3 4)))))
+   (assert-equal 'empty
+		 (uim '(iterate-lists (lambda (state elms)
+					(if (null? elms)
+					    (cons #t state)
+					    (cons #f (cons elms state))))
+				      'empty
+				      '(("h" "e" "l" "l" "o")
+					()
+					(0 1 2 3 4))))))
 
   ;; compare string sequence
   ("test str-seq-equal?"

Modified: trunk/uim/uim-util.c
===================================================================
--- trunk/uim/uim-util.c	2005-08-22 05:56:08 UTC (rev 1273)
+++ trunk/uim/uim-util.c	2005-08-22 06:10:51 UTC (rev 1274)
@@ -508,7 +508,7 @@
   uim_lisp elms, rest, rests, mapped, res, termp, pair, form;
   uim_bool single_listp;
 
-  single_listp = (uim_scm_length(lists) == 1) ? UIM_TRUE : UIM_FALSE;
+  single_listp = uim_scm_nullp(uim_scm_cdr(lists));
   res = seed;
   if (single_listp) {
     rest = uim_scm_car(lists);
@@ -518,8 +518,12 @@
   do {
     if (single_listp) {
       /* fast path */
-      elms = uim_scm_list1(uim_scm_car(rest));
-      rest = uim_scm_cdr(rest);
+      if (uim_scm_nullp(rest)) {
+	elms = uim_scm_null_list();
+      } else {
+	elms = uim_scm_list1(uim_scm_car(rest));
+	rest = uim_scm_cdr(rest);
+      }
     } else {
       pair = shift_elems(rests);
       if (FALSEP(pair)) {



More information about the uim-commit mailing list