[uim-commit] r2869 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Mon Jan 9 08:03:50 PST 2006


Author: yamaken
Date: 2006-01-09 08:03:46 -0800 (Mon, 09 Jan 2006)
New Revision: 2869

Modified:
   branches/r5rs/sigscheme/eval.c
   branches/r5rs/sigscheme/io.c
   branches/r5rs/sigscheme/operations-nonstd.c
   branches/r5rs/sigscheme/operations-siod.c
   branches/r5rs/sigscheme/operations.c
   branches/r5rs/sigscheme/storage.c
   branches/r5rs/sigscheme/write.c
Log:
* sigscheme/storage.c
  - (scm_make_string_internal):
    * Eliminate never met condition
    * Optimize for empty string
* sigscheme/write.c
  - (write_errobj): Simplify with FOR_EACH()
* sigscheme/io.c
  - (scm_prepare_port): Optimize for procedure call which ensures
    proper variadic args
* sigscheme/operations-nonstd.c
  - (scm_p_symbol_boundp): Ditto
* sigscheme/operations-siod.c
  - (scm_p_verbose): Ditto
* sigscheme/eval.c
  - (scm_p_apply): Ditto
* sigscheme/operations.c
  - (prepare_radix, scm_p_make_string, scm_p_make_vector,
    map_multiple_args): Ditto
  - (scm_p_string_append):
    * Ditto
    * Optimize string construction


Modified: branches/r5rs/sigscheme/eval.c
===================================================================
--- branches/r5rs/sigscheme/eval.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/eval.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -443,7 +443,7 @@
     ScmObj args, arg, last;
     DECLARE_FUNCTION("apply", procedure_variadic_tailrec_2);
 
-    if (NO_MORE_ARG(rest)) {
+    if (NULLP(rest)) {
         args = last = arg0;
     } else {
         /* More than one argument given. */

Modified: branches/r5rs/sigscheme/io.c
===================================================================
--- branches/r5rs/sigscheme/io.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/io.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -118,13 +118,15 @@
     ScmObj port;
     DECLARE_INTERNAL_FUNCTION("prepare_port");
 
-    if (CONSP(args)) {
+    ASSERT_PROPER_ARG_LIST(args);
+
+    if (NULLP(args)) {
+        port = default_port;
+    } else {
         port = POP(args);
+        ASSERT_NO_MORE_ARG(args);
         ENSURE_PORT(port);
-    } else {
-        port = default_port;
     }
-    ASSERT_NO_MORE_ARG(args);
 
     return port;
 }

Modified: branches/r5rs/sigscheme/operations-nonstd.c
===================================================================
--- branches/r5rs/sigscheme/operations-nonstd.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/operations-nonstd.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -93,12 +93,12 @@
 
     ENSURE_SYMBOL(sym);
 
-    if (CONSP(rest)) {
+    if (NULLP(rest)) {
+        env = SCM_INTERACTION_ENV;
+    } else {
         env = POP(rest);
         ASSERT_NO_MORE_ARG(rest);
         ENSURE_VALID_ENV(env);
-    } else {
-        env = SCM_INTERACTION_ENV;
     }
     ref = scm_lookup_environment(sym, env);
 

Modified: branches/r5rs/sigscheme/operations-siod.c
===================================================================
--- branches/r5rs/sigscheme/operations-siod.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/operations-siod.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -202,7 +202,7 @@
     ScmObj level;
     DECLARE_FUNCTION("verbose", procedure_variadic_0);
 
-    if (CONSP(args)) {
+    if (!NULLP(args)) {
         level = POP(args);
         ASSERT_NO_MORE_ARG(args);
         ENSURE_INT(level);

Modified: branches/r5rs/sigscheme/operations.c
===================================================================
--- branches/r5rs/sigscheme/operations.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/operations.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -553,18 +553,20 @@
     int r;
     DECLARE_INTERNAL_FUNCTION("(internal)");
 
+    ASSERT_PROPER_ARG_LIST(args);
+
     /* dirty hack to replace internal function name */
     SCM_MANGLE(name) = funcname;
 
-    if (CONSP(args)) {
+    if (NULLP(args)) {
+        r = 10;
+    } else {
         radix = POP(args);
         ASSERT_NO_MORE_ARG(args);
         ENSURE_INT(radix);
         r = SCM_INT_VALUE(radix);
-      if (!(r == 2 || r == 8 || r == 10 || r == 16))
-          ERR_OBJ("invalid radix", radix);
-    } else {
-        r = 10;
+        if (!(r == 2 || r == 8 || r == 10 || r == 16))
+            ERR_OBJ("invalid radix", radix);
     }
 
     return r;
@@ -1260,7 +1262,7 @@
         ERR_OBJ("length must be a positive integer", length);
 
     /* extract filler */
-    if (NO_MORE_ARG(args)) {
+    if (NULLP(args)) {
         filler_val = ' ';
     } else {
         filler = POP(args);
@@ -1440,40 +1442,41 @@
 }
 
 /* FIXME: support stateful encoding */
-/* TODO: improve average performance for uim */
 ScmObj
 scm_p_string_append(ScmObj args)
 {
-    ScmObj rest, str;
+    ScmObj rest, str, ret;
     size_t byte_len, mb_len;
-    char  *new_str, *p;
+    char  *new_str, *dst;
+    const char *src;
     DECLARE_FUNCTION("string-append", procedure_variadic_0);
 
-    if (NO_MORE_ARG(args))
+    if (NULLP(args))
         return MAKE_STRING_COPYING("");
 
     /* count total size of the new string */
-    for (byte_len = mb_len = 0, rest = args; CONSP(rest); rest = CDR(rest)) {
-        str = CAR(rest);
+    byte_len = mb_len = 0;
+    rest = args;
+    FOR_EACH (str, rest) {
         ENSURE_STRING(str);
-
         byte_len += strlen(SCM_STRING_STR(str));
         mb_len   += SCM_STRING_LEN(str);
     }
-    ENSURE_PROPER_LIST_TERMINATION(rest, args);
 
     new_str = scm_malloc(byte_len + sizeof(""));
 
     /* copy all strings into new_str */
-    for (p = new_str, rest = args; !NULLP(rest); rest = CDR(rest)) {
-        str = CAR(rest);
-
-        /* expensive */
-        strcpy(p, SCM_STRING_STR(str));
-        p += strlen(SCM_STRING_STR(str));
+    dst = new_str;
+    FOR_EACH (str, args) {
+        for (src = SCM_STRING_STR(str); *src;)
+            *dst++ = *src++;
     }
 
-    return MAKE_STRING(new_str);
+    ret = MAKE_STRING((char *)"");  /* dummy string */
+    SCM_STRING_SET_STR(ret, new_str);
+    SCM_STRING_SET_LEN(ret, mb_len);
+
+    return ret;
 }
 
 ScmObj
@@ -1594,7 +1597,12 @@
         ERR_OBJ("length must be a positive integer", scm_len);
 
     vec = scm_malloc(sizeof(ScmObj) * len);
-    filler = (CONSP(args)) ? CAR(args) : SCM_UNDEF;
+    if (NULLP(args)) {
+        filler = SCM_UNDEF;
+    } else {
+        filler = POP(args);
+        ASSERT_NO_MORE_ARG(args);
+    }
     for (i = 0; i < len; i++)
         vec[i] = filler;
 
@@ -1770,16 +1778,15 @@
         SCM_QUEUE_POINT_TO(argq, map_args);
         for (rest_args = args; CONSP(rest_args); rest_args = CDR(rest_args)) {
             arg = CAR(rest_args);
-            if (NULLP(arg))
-                return res;
             if (CONSP(arg))
                 SCM_QUEUE_ADD(argq, CAR(arg));
+            else if (NULLP(arg))
+                return res;
             else
                 ERR_OBJ("invalid argument", arg);
             /* pop destructively */
             SET_CAR(rest_args, CDR(arg));
         }
-        ENSURE_PROPER_LIST_TERMINATION(rest_args, args);
 
         elm = scm_call(proc, map_args);
         SCM_QUEUE_ADD(resq, elm);

Modified: branches/r5rs/sigscheme/storage.c
===================================================================
--- branches/r5rs/sigscheme/storage.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/storage.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -213,7 +213,7 @@
     obj = scm_alloc_cell();
     SCM_ENTYPE_STRING(obj);
     SCM_STRING_SET_STR(obj, str);
-    SCM_STRING_SET_LEN(obj, str ? scm_mb_bare_c_strlen(str) : 0);
+    SCM_STRING_SET_LEN(obj, (*str) ? scm_mb_bare_c_strlen(str) : 0);
 
     if (is_immutable)
         SCM_STRING_SET_IMMUTABLE(obj);

Modified: branches/r5rs/sigscheme/write.c
===================================================================
--- branches/r5rs/sigscheme/write.c	2006-01-09 12:15:59 UTC (rev 2868)
+++ branches/r5rs/sigscheme/write.c	2006-01-09 16:03:46 UTC (rev 2869)
@@ -470,7 +470,7 @@
 static void
 write_errobj(ScmObj port, ScmObj obj, enum  OutputType otype)
 {
-    ScmObj err_obj_tag, reason, objs, trace_stack;
+    ScmObj err_obj_tag, reason, objs, trace_stack, elm;
     DECLARE_INTERNAL_FUNCTION("write_errobj");
 
     err_obj_tag = MUST_POP_ARG(obj);
@@ -496,9 +496,9 @@
         break;
     }
 
-    for (; CONSP(objs); objs = CDR(objs)) {
+    FOR_EACH(elm, objs) {
         scm_port_put_char(port, ' ');
-        scm_write_to_port(port, CAR(objs));
+        scm_write_to_port(port, elm);
     }
 
     if (otype == AS_WRITE)



More information about the uim-commit mailing list