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

yamaken at freedesktop.org yamaken at freedesktop.org
Thu Jan 12 11:41:05 PST 2006


Author: yamaken
Date: 2006-01-12 11:41:00 -0800 (Thu, 12 Jan 2006)
New Revision: 2895

Modified:
   branches/r5rs/sigscheme/TODO
   branches/r5rs/sigscheme/operations.c
Log:
* sigscheme/operations.c
  - (scm_p_integer2char, scm_p_make_string, scm_p_string_length,
    scm_p_string_ref, scm_p_string_setd, scm_p_substring,
    scm_p_string_append, scm_p_string2list, scm_p_list2string,
    scm_p_string_filld): Simplify and make efficient singlebyte
    processing
* sigscheme/TODO
  - Update


Modified: branches/r5rs/sigscheme/TODO
===================================================================
--- branches/r5rs/sigscheme/TODO	2006-01-11 00:43:17 UTC (rev 2894)
+++ branches/r5rs/sigscheme/TODO	2006-01-12 19:41:00 UTC (rev 2895)
@@ -116,8 +116,6 @@
 ==============================================================================
 Assigned to YamaKen:
 
-* Simplify string and character operations if !SCM_USE_MULTIBYTE_CHAR
-
 * Write tests for SRFI-75
 
 * Add integer->char and char->integer procedures with multibyte support

Modified: branches/r5rs/sigscheme/operations.c
===================================================================
--- branches/r5rs/sigscheme/operations.c	2006-01-11 00:43:17 UTC (rev 2894)
+++ branches/r5rs/sigscheme/operations.c	2006-01-12 19:41:00 UTC (rev 2895)
@@ -1192,8 +1192,13 @@
     ENSURE_INT(n);
 
     val = SCM_INT_VALUE(n);
+#if SCM_USE_MULTIBYTE_CHAR
     if (!SCM_CHARCODEC_CHAR_LEN(scm_current_char_codec, val))
+#else
+    if (!isascii(val))
+#endif
         ERR_OBJ("invalid char value", n);
+
     return MAKE_CHAR(val);
 }
 
@@ -1244,8 +1249,10 @@
     ScmObj filler;
     int filler_val, len, ch_len;
     char *str, *dst;
+#if SCM_USE_MULTIBYTE_CHAR
     const char *next;
     char ch_str[SCM_MB_MAX_LEN + sizeof("")];
+#endif
     DECLARE_FUNCTION("make-string", procedure_variadic_1);
 
     ENSURE_STATELESS_CODEC(scm_current_char_codec);
@@ -1265,13 +1272,16 @@
         ASSERT_NO_MORE_ARG(args);
         ENSURE_CHAR(filler);
         filler_val = SCM_CHAR_VALUE(filler);
+#if SCM_USE_MULTIBYTE_CHAR
         ch_len = SCM_CHARCODEC_CHAR_LEN(scm_current_char_codec, filler_val);
+#endif
     }
 #if !SCM_USE_NULL_CAPABLE_STRING
     if (filler_val == '\0')
         ERR("make-string: " SCM_ERRMSG_NULL_IN_STRING);
 #endif
 
+#if SCM_USE_MULTIBYTE_CHAR
     next = SCM_CHARCODEC_INT2STR(scm_current_char_codec, ch_str, filler_val,
                                  SCM_MB_STATELESS);
     if (!next)
@@ -1281,6 +1291,12 @@
     str = scm_malloc(ch_len * len + sizeof(""));
     for (dst = str; dst < &str[ch_len * len]; dst += ch_len)
         memcpy(dst, ch_str, ch_len);
+#else
+    SCM_ASSERT(isascii(filler_val));
+    str = scm_malloc(len + sizeof(""));
+    for (dst = str; dst < &str[len];)
+        *dst++ = filler_val;
+#endif
     *dst = '\0';
 
     return MAKE_STRING(str, len);
@@ -1302,7 +1318,11 @@
 
     ENSURE_STRING(str);
 
+#if SCM_USE_MULTIBYTE_CHAR
     len = scm_mb_bare_c_strlen(scm_current_char_codec, SCM_STRING_STR(str));
+#else
+    len = SCM_STRING_LEN(str);
+#endif
 
     return MAKE_INT(len);
 }
@@ -1311,7 +1331,9 @@
 scm_p_string_ref(ScmObj str, ScmObj k)
 {
     int idx, ch;
+#if SCM_USE_MULTIBYTE_CHAR
     ScmMultibyteString mbs;
+#endif
     DECLARE_FUNCTION("string-ref", procedure_fixed_2);
 
     ENSURE_STRING(str);
@@ -1321,6 +1343,7 @@
     if (idx < 0 || SCM_STRING_LEN(str) <= idx)
         ERR_OBJ("index out of range", k);
 
+#if SCM_USE_MULTIBYTE_CHAR
     SCM_MBS_INIT2(mbs, SCM_STRING_STR(str), strlen(SCM_STRING_STR(str)));
     mbs = scm_mb_strref(scm_current_char_codec, mbs, idx);
 
@@ -1328,6 +1351,9 @@
                                SCM_MBS_GET_SIZE(mbs), SCM_MBS_GET_STATE(mbs));
     if (ch == EOF)
         ERR("string-ref: invalid char sequence");
+#else
+    ch = ((unsigned char *)SCM_STRING_STR(str))[idx];
+#endif
 
     return MAKE_CHAR(ch);
 }
@@ -1335,12 +1361,16 @@
 ScmObj
 scm_p_string_setd(ScmObj str, ScmObj k, ScmObj ch)
 {
-    int ch_val, idx, ch_len, orig_ch_len;
+    int idx, ch_val;
+    char *c_str;
+#if SCM_USE_MULTIBYTE_CHAR
+    int ch_len, orig_ch_len;
     size_t prefix_len, suffix_len, new_str_len;
     const char *suffix_src, *ch_end;
-    char *c_str, *new_str, *suffix_dst;
+    char *new_str, *suffix_dst;
     char ch_buf[SCM_MB_MAX_LEN + sizeof("")];
     ScmMultibyteString mbs_ch;
+#endif
     DECLARE_FUNCTION("string-set!", procedure_fixed_3);
 
     ENSURE_STATELESS_CODEC(scm_current_char_codec);
@@ -1354,6 +1384,7 @@
     if (idx < 0 || SCM_STRING_LEN(str) <= idx)
         ERR_OBJ("index out of range", k);
 
+#if SCM_USE_MULTIBYTE_CHAR
     /* point at the char that to be replaced */
     SCM_MBS_INIT2(mbs_ch, c_str, strlen(c_str));
     mbs_ch = scm_mb_strref(scm_current_char_codec, mbs_ch, idx);
@@ -1389,6 +1420,11 @@
     memcpy(&new_str[prefix_len], ch_buf, ch_len);
 
     SCM_STRING_SET_STR(str, new_str);
+#else
+    ch_val = SCM_CHAR_VALUE(ch);
+    SCM_ASSERT(isascii(ch_val));
+    c_str[idx] = ch_val;
+#endif
 
     return str;
 }
@@ -1407,10 +1443,12 @@
 ScmObj
 scm_p_substring(ScmObj str, ScmObj start, ScmObj end)
 {
-    int c_start, c_end, len;
+    int c_start, c_end, len, sub_len;
     const char *c_str;
     char *new_str;
+#if SCM_USE_MULTIBYTE_CHAR
     ScmMultibyteString mbs;
+#endif
     DECLARE_FUNCTION("substring", procedure_fixed_3);
 
     ENSURE_STRING(str);
@@ -1428,22 +1466,29 @@
     if (c_start > c_end)
         ERR_OBJ("start index exceeded end index", LIST_2(start, end));
 
+    c_str = SCM_STRING_STR(str);
+    sub_len = c_end - c_start;
+
+#if SCM_USE_MULTIBYTE_CHAR
     /* substring */
-    c_str = SCM_STRING_STR(str);
     SCM_MBS_INIT2(mbs, c_str, strlen(c_str));
-    mbs = scm_mb_substring(scm_current_char_codec,
-                           mbs, c_start, c_end - c_start);
+    mbs = scm_mb_substring(scm_current_char_codec, mbs, c_start, sub_len);
 
     /* copy the substring */
     new_str = scm_malloc(SCM_MBS_GET_SIZE(mbs) + sizeof(""));
     memcpy(new_str, SCM_MBS_GET_STR(mbs), SCM_MBS_GET_SIZE(mbs));
     new_str[SCM_MBS_GET_SIZE(mbs)] = '\0';
+#else
+    new_str = scm_malloc(sub_len + sizeof(""));
+    memcpy(new_str, &c_str[c_start], sub_len);
+    new_str[sub_len] = '\0';
+#endif
 
 #if SCM_USE_NULL_CAPABLE_STRING
     /* FIXME: the result is truncated at null and incorrect */
     return MAKE_STRING(new_str, STRLEN_UNKNOWN);
 #else
-    return MAKE_STRING(new_str, c_end - c_start);
+    return MAKE_STRING(new_str, sub_len);
 #endif
 }
 
@@ -1465,8 +1510,12 @@
     rest = args;
     FOR_EACH (str, rest) {
         ENSURE_STRING(str);
+        mb_len   += SCM_STRING_LEN(str);
+#if SCM_USE_MULTIBYTE_CHAR
         byte_len += strlen(SCM_STRING_STR(str));
-        mb_len   += SCM_STRING_LEN(str);
+#else
+        byte_len = mb_len;
+#endif
     }
 
     new_str = scm_malloc(byte_len + sizeof(""));
@@ -1490,21 +1539,24 @@
 ScmObj
 scm_p_string2list(ScmObj str)
 {
+#if SCM_USE_MULTIBYTE_CHAR
+    ScmMultibyteString mbs;
     ScmQueue q;
+#endif
     ScmObj res;
     int ch, mb_len;
     const char *c_str;
-    ScmMultibyteString mbs;
     DECLARE_FUNCTION("string->list", procedure_fixed_1);
 
     ENSURE_STRING(str);
 
     c_str = SCM_STRING_STR(str);
     mb_len = SCM_STRING_LEN(str);
-    SCM_MBS_INIT2(mbs, c_str, strlen(c_str));
 
     res = SCM_NULL;
+#if SCM_USE_MULTIBYTE_CHAR
     SCM_QUEUE_POINT_TO(q, res);
+    SCM_MBS_INIT2(mbs, c_str, strlen(c_str));
     while (mb_len--) {
         if (SCM_MBS_GET_SIZE(mbs)) {
             ch = SCM_CHARCODEC_READ_CHAR(scm_current_char_codec, mbs);
@@ -1517,10 +1569,16 @@
             SCM_MBS_INIT2(mbs, c_str, strlen(c_str));
 #else
             break;
-#endif
+#endif /* SCM_USE_NULL_CAPABLE_STRING */
         }
         SCM_QUEUE_ADD(q, MAKE_CHAR(ch));
     }
+#else /* SCM_USE_MULTIBYTE_CHAR */
+    while (mb_len) {
+        ch = ((unsigned char *)c_str)[--mb_len];
+        res = CONS(MAKE_CHAR(ch), res);
+    }
+#endif /* SCM_USE_MULTIBYTE_CHAR */
 
     return res;
 }
@@ -1530,8 +1588,11 @@
 {
     ScmObj rest, ch;
     size_t str_size;
-    int ch_val, len;
+    int len;
     char *str, *dst;
+#if SCM_USE_MULTIBYTE_CHAR
+    int ch_val;
+#endif
     DECLARE_FUNCTION("list->string", procedure_fixed_1);
 
     ENSURE_STATELESS_CODEC(scm_current_char_codec);
@@ -1545,8 +1606,12 @@
     len = 0;
     FOR_EACH (ch, rest) {
         ENSURE_CHAR(ch);
+#if SCM_USE_MULTIBYTE_CHAR
         ch_val = SCM_CHAR_VALUE(ch);
         str_size += SCM_CHARCODEC_CHAR_LEN(scm_current_char_codec, ch_val);
+#else
+        str_size++;
+#endif
         len++;
     }
     ENSURE_PROPER_LIST_TERMINATION(rest, lst);
@@ -1557,9 +1622,16 @@
         if (ch == '\0')
             ERR("list->string: " SCM_ERRMSG_NULL_IN_STRING);
 #endif
+#if SCM_USE_MULTIBYTE_CHAR
         dst = SCM_CHARCODEC_INT2STR(scm_current_char_codec, dst,
                                     SCM_CHAR_VALUE(ch), SCM_MB_STATELESS);
+#else
+        *dst++ = SCM_CHAR_VALUE(ch);
+#endif
     }
+#if !SCM_USE_MULTIBYTE_CHAR
+    *dst = '\0';
+#endif
 
     return MAKE_STRING(str, len);
 }
@@ -1582,10 +1654,17 @@
 ScmObj
 scm_p_string_filld(ScmObj str, ScmObj ch)
 {
-    int  ch_len, str_len;
-    char *new_str, *p;
+    int str_len;
+    char *dst;
+#if SCM_USE_MULTIBYTE_CHAR
+    int ch_len;
+    char *new_str;
     char ch_str[SCM_MB_MAX_LEN + sizeof("")];
     const char *next;
+#else
+    int ch_val;
+    char *c_str;
+#endif
     DECLARE_FUNCTION("string-fill!", procedure_fixed_2);
 
     ENSURE_STATELESS_CODEC(scm_current_char_codec);
@@ -1597,6 +1676,7 @@
     if (str_len == 0)
         return MAKE_STRING_COPYING("", 0);
 
+#if SCM_USE_MULTIBYTE_CHAR
     next = SCM_CHARCODEC_INT2STR(scm_current_char_codec, ch_str,
                                  SCM_CHAR_VALUE(ch), SCM_MB_STATELESS);
     if (!next)
@@ -1607,11 +1687,18 @@
     /* create new str */
     ch_len = next - ch_str;
     new_str = scm_realloc(SCM_STRING_STR(str), str_len * ch_len + sizeof(""));
-    for (p = new_str; p < &new_str[ch_len * str_len]; p += ch_len)
-        memcpy(p, ch_str, ch_len);
-    *p = '\0';
+    for (dst = new_str; dst < &new_str[ch_len * str_len]; dst += ch_len)
+        memcpy(dst, ch_str, ch_len);
+    *dst = '\0';
 
     SCM_STRING_SET_STR(str, new_str);
+#else
+    ch_val = SCM_CHAR_VALUE(ch);
+    SCM_ASSERT(isascii(ch_val));
+    c_str = SCM_STRING_STR(str);
+    for (dst = c_str; dst < &c_str[str_len]; dst++)
+        *dst = ch_val;
+#endif
 
     return str;
 }



More information about the uim-commit mailing list